From: Bryan Date: Fri, 10 Jan 2014 08:50:25 +0000 (-0500) Subject: serious hacking to deal with existing FK data in Note. X-Git-Tag: release-20150131~285 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=38ae22cfb6649dbcea2ffa1e67d12c02606c5809;p=oweals%2Fkarmaworld.git serious hacking to deal with existing FK data in Note. --- diff --git a/karmaworld/apps/users/migrations/0002_auto__del_karmauser__add_userprofile.py b/karmaworld/apps/users/migrations/0002_auto__del_karmauser__add_userprofile.py index da99aed..b4404d8 100644 --- a/karmaworld/apps/users/migrations/0002_auto__del_karmauser__add_userprofile.py +++ b/karmaworld/apps/users/migrations/0002_auto__del_karmauser__add_userprofile.py @@ -9,8 +9,15 @@ from karmaworld.apps.notes.models import Note class Migration(SchemaMigration): def forwards(self, orm): - # Removing all possible FK dependencies on KarmaUser from Note - Note.objects.update(user=None) + # This should not be done here, but there is already a migration in + # Notes which relies on this migration. So this must be done here. + # Used VM to generate a migration to convert FK into Int. + # Renaming column for 'Note.user' to match new field type. + db.rename_column('notes_note', 'user_id', 'user') + # Changing field 'Note.user' + db.alter_column('notes_note', 'user', self.gf('django.db.models.fields.IntegerField')(null=True)) + # Removing index on 'Note', fields ['user'] + db.delete_index('notes_note', ['user_id']) # Deleting model 'KarmaUser' db.delete_table('users_karmauser') @@ -38,6 +45,13 @@ class Migration(SchemaMigration): # Deleting model 'UserProfile' db.delete_table('users_userprofile') + # This should not be done here, but there is already a migration in + # Notes which relies on this migration. So this must be done here. + # Used VM to generate a migration to convert FK into Int. + # Renaming column for 'Note.user' to match new field type. + db.rename_column('notes_note', 'user', 'user_id') + # Changing field 'Note.user' + db.alter_column('notes_note', 'user_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['users.KarmaUser'], null=True, on_delete=models.SET_NULL)) models = { 'auth.group': {