-
Notifications
You must be signed in to change notification settings - Fork 18
Using a different User model than accounts.BlueBottleUser
When using a different user model than BlueBottleUser (extending BlueBottleBaseUser)
$ python manage.py schemamigration members --initial
Edit the generated initial migration file:
-
Check the diffs with the bluebottle user model and copy those field definitions, e.g.
self.gf('django.db.models.fields.CharField')(max_length=255)
-
Replace the create_table statement with db.add_column(u'accounts_bluebottleuser', 'field_name', field_definition_from_step_1)
-
Keep the M2M fields/tables you added.
-
Add the depends_on for migration order: depends_on = ( ('accounts', '0001_initial'), )
- your own dependencies
-
Remove the create table statements for accounts_bluebottleuser_groups, accounts_bluebottleuser_user_permissions, BUT make sure to replace them with the renaming of columns:
m2m_table_name = db.shorten_name('accounts_bluebottleuser_groups') db.delete_unique(m2m_table_name, ['bluebottleuser_id', 'group_id']) db.rename_column(m2m_table_name, 'bluebottleuser_id', '%s_id' % model_name) db.create_unique(m2m_table_name, ['%s_id' % model_name, 'group_id'])
m2m_table_name = db.shorten_name('accounts_bluebottleuser_user_permissions') db.delete_unique(m2m_table_name, ['bluebottleuser_id', 'permission_id']) db.rename_column(m2m_table_name, 'bluebottleuser_id', '%s_id' % model_name) db.create_unique(m2m_table_name, ['%s_id' % model_name, 'permission_id'])
-
Edit the backwards migration: replace the db.delete_table with the appropriate db.delete_column (inverse of the forwards migration)
-
Backwards migration: remove the delete table statements for accounts_bluebottleuser_groups, accounts_bluebottleuser_user_permissions and replace with:
m2m_table_name = db.shorten_name('accounts_bluebottleuser_groups') db.rename_column(m2m_table_name, '%s_id' % model_name, 'bluebottleuser_id') db.delete_unique(m2m_table_name, ['%s_id' % model_name, 'group_id']) db.create_unique(m2m_table_name, ['bluebottleuser_id', 'group_id'])
m2m_table_name = db.shorten_name('accounts_bluebottleuser_user_permissions') db.rename_column(m2m_table_name, '%s_id' % model_name, 'bluebottleuser_id') db.delete_unique(m2m_table_name, ['%s_id' % model_name, 'permission_id']) db.create_unique(m2m_table_name, ['bluebottleuser_id', 'permission_id'])