Skip to content

Using a different User model than accounts.BlueBottleUser

Sergei Maertens edited this page Jan 14, 2014 · 1 revision

When using a different user model than BlueBottleUser (extending BlueBottleBaseUser)

$ python manage.py schemamigration members --initial

Edit the generated initial migration file:

  1. 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)

  2. Replace the create_table statement with db.add_column(u'accounts_bluebottleuser', 'field_name', field_definition_from_step_1)

  3. Keep the M2M fields/tables you added.

  4. Add the depends_on for migration order: depends_on = ( ('accounts', '0001_initial'), )

    • your own dependencies
  5. Remove the create table statements for accounts_bluebottleuser_groups, accounts_bluebottleuser_user_permissions, BUT make sure to replace them with the renaming of columns:

    Mofiyfing M2M table for field groups on 'BookingUser'

    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'])

    Mofiyfing M2M table for field user_permissions on 'BookingUser'

    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'])

  6. Edit the backwards migration: replace the db.delete_table with the appropriate db.delete_column (inverse of the forwards migration)

  7. Backwards migration: remove the delete table statements for accounts_bluebottleuser_groups, accounts_bluebottleuser_user_permissions and replace with:

    Mofiyfing M2M table for field groups on 'BookingUser'

    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'])

    Mofiyfing M2M table for field user_permissions on 'BookingUser'

    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'])