From 38ae22cfb6649dbcea2ffa1e67d12c02606c5809 Mon Sep 17 00:00:00 2001 From: Bryan Date: Fri, 10 Jan 2014 03:50:25 -0500 Subject: [PATCH] serious hacking to deal with existing FK data in Note. --- ...002_auto__del_karmauser__add_userprofile.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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': { -- 2.25.1