ValueError with initial migration #593

tejinderss opened this Issue Jan 30, 2013 · 15 comments


None yet
9 participants

ValueError: Cannot successfully create field 'user' for model 'usersocialauth': "The model 'customuser' from the app 'profiles' is not available in this migration.".

Here are the settings:
AUTH_USER_MODEL = 'profiles.CustomUser'
SOCIAL_AUTH_USER_MODEL = 'profiles.CustomUser'

I have put my 'profiles' app in settings module. Here is the file:
class CustomUser(AbstractUser):
index = models.PositiveIntegerField(_('index'),
default=0, blank=True)

I can get this model using get_auth_model() successfully. Any idea what is going on?


omab commented Jan 30, 2013

There seems to be some issues with south migrations and custom user models, I need to investigate it.


syabro commented Feb 12, 2013

Same stuff here.
Custom user.


ulyssesv commented Feb 15, 2013


The custom User model isn't frozen inside the South migrations so accessing orm[USER_MODEL] doesn't work.

An ugly and temporary workaround is to add the model to the south migrations:

    models = {
        'account.user': {
            'Meta': {'object_name': 'User'},
            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': ''}),
            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': ''}),
            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})

    complete_apps = ['social_auth', 'account']

omab added a commit that referenced this issue Feb 16, 2013


omab commented Feb 16, 2013

I've updated the migrations to be built dynamically from models instead of some static fields definition, it seems to work, anybody could give it a try again?


ghost commented Feb 17, 2013

I tried to install django-social-auth (PyPi, stable) with new project, but got same error (ValueError: Cannot successfully create field), next I tried latest dev version from trunk and got this error:

Error in migration: social_auth:0002_auto__add_unique_nonce_timestamp_salt_server_url__add_unique_associati
DatabaseError: relation "social_auth_nonce_timestamp" already exists


DatabaseError: relation "social_auth_association_issued" already exists

I manually removed this indexes from database after first migration and tried migrate 0002 again and it works now.. So may be you need remove 4 lines with 'create_index' and 'delete_index' in /social_auth/migrations/ to fix this issue...


omab commented Feb 17, 2013

@lorddaedra, seems to me that the changes are already in place, try running with --fake.


ghost commented Feb 22, 2013

@omab with --fake I lose this unique indexes:

        db.create_unique(Nonce._meta.db_table, ['timestamp', 'salt',
        db.create_unique(Association._meta.db_table, ['handle', 'server_url'])

oinopion added a commit to oinopion/django-social-auth that referenced this issue Feb 27, 2013


any ideas how to fix this bug? I hit similar one with django-admin-tools,


oinopion commented Mar 1, 2013

Use SOUTH_MIGRATION_MODULES to specify alternative migrations directory for social auth, then do schemamigration --initial social_auth. This way you will have to take care of creating new migrations yourself, but you will not have problems with custom user model.

Handy documentation link:

Here's what fixed the migrations for me, does anybody have opinion on such approach? :


omab commented Mar 4, 2013

@tejinderss, the fix done by @oinopion is merged into master branch, please take a look, it solves the issue. Reopen if it's not the case.

@omab omab closed this Mar 4, 2013

dbrgn commented Apr 19, 2013

I installed django-social-auth from current master (commit d444f82), but the migration still doesn't work:

(radar-django)[master]danilo@t410:radar$ ./ migrate
Running migrations for social_auth:
 - Migrating forwards to 0002_auto__add_unique_nonce_timestamp_salt_server_url__add_unique_associati.
 > social_auth:0001_initial
ValueError: Cannot successfully create field 'user' for model 'usersocialauth': "The model 'user' from the app 'front' is not available in this migration.".

caioariede commented May 22, 2013

@dbrgn just make sure you have INITIAL_CUSTOM_USER_MIGRATION pointing to the correct migration, in case your model was created in other migration than


rca commented Jul 19, 2013

I added INITIAL_CUSTOM_USER_MIGRATION to and get the following error:

FATAL ERROR - The following SQL query failed: ALTER TABLE "social_auth_usersocialauth" ADD CONSTRAINT "user_id_refs_id_69f19872bc0e7859" FOREIGN KEY ("user_id") REFERENCES "console_baremetaluser" ("id") DEFERRABLE INITIALLY DEFERRED;
The error was: relation "console_baremetaluser" does not exist

DatabaseError: relation "console_baremetaluser" does not exist

rca commented Jul 19, 2013

I figured out that the app with the custom user model has to be listed before south/social_auth in INSTALLED_APPS. After moving it up the migration worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment