pennersr / django-allauth

Integrated set of Django applications addressing authentication, registration, account management as well as 3rd party (social) account authentication.
https://allauth.org
MIT License
9.41k stars 3.01k forks source link

Error during South migration with Twitter provider #449

Closed akoumjian closed 10 years ago

akoumjian commented 10 years ago

On a fresh 1.6 project, I am attempting to initialize my database. For some reason, get_user_model() is failing during one of the twitter migrations.

Here are the installed apps:

INSTALLED_APPS = (
    ...
    'django.contrib.auth',
    ...
    'south',
    'allauth',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.twitter',
    ...
)

This results in the following output and error during ./manage.py migrate --all:

(announce)~/Code/announce(master ✗) ./manage.py migrate --all
Running migrations for socialaccount:
 - Migrating forwards to 0011_auto__chg_field_socialtoken_token.
 > socialaccount:0001_initial
 > twitter:0001_initial
 > twitter:0002_snowflake
 > socialaccount:0002_genericmodels
 > twitter:0003_tosocialaccount
 - Migration 'twitter:0003_tosocialaccount' is marked for no-dry-run.
 > socialaccount:0003_auto__add_unique_socialaccount_uid_provider
 > socialaccount:0004_add_sites
 > socialaccount:0005_set_sites
 - Migration 'socialaccount:0005_set_sites' is marked for no-dry-run.
 > socialaccount:0006_auto__del_field_socialapp_site
 > socialaccount:0007_auto__add_field_socialapp_client_id
 > socialaccount:0008_client_id
 - Migration 'socialaccount:0008_client_id' is marked for no-dry-run.
 > socialaccount:0009_auto__add_field_socialtoken_expires_at
 > socialaccount:0010_auto__chg_field_socialtoken_token
 > socialaccount:0011_auto__chg_field_socialtoken_token
 - Loading initial data for socialaccount.
Installed 0 object(s) from 0 fixture(s)
Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/aleck/.virtualenvs/announce/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/Users/aleck/.virtualenvs/announce/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/aleck/.virtualenvs/announce/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Users/aleck/.virtualenvs/announce/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/Users/aleck/.virtualenvs/announce/lib/python2.7/site-packages/south/management/commands/migrate.py", line 111, in handle
    ignore_ghosts = ignore_ghosts,
  File "/Users/aleck/.virtualenvs/announce/lib/python2.7/site-packages/south/migration/__init__.py", line 179, in migrate_app
    Migrations.invalidate_all_modules()
  File "/Users/aleck/.virtualenvs/announce/lib/python2.7/site-packages/south/migration/base.py", line 237, in invalidate_all_modules
    migration.invalidate_module()
  File "/Users/aleck/.virtualenvs/announce/lib/python2.7/site-packages/south/migration/base.py", line 381, in invalidate_module
    reload(self.migration())
  File "/Users/aleck/.virtualenvs/announce/lib/python2.7/site-packages/allauth/socialaccount/migrations/0001_initial.py", line 11, in <module>
    User = get_user_model()
  File "/Users/aleck/.virtualenvs/announce/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 122, in get_user_model
    raise ImproperlyConfigured("AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL)
django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'auth.User' that has not been installed
pennersr commented 10 years ago

Are you using a custom user model? Btw, given that you are on a fresh db, migrating is not needed anyway, so you could have simply run syncdb --all

lucacorti commented 10 years ago

OK, so this is the same issue I am experiencing. I don't have a fresh database though, and I get this every time I run manage.py migrate. Also, running only socialaccount migrations does not cause the error:

$ python manage.py migrate allauth.socialaccount
Running migrations for socialaccount:
- Nothing to migrate.
 - Loading initial data for socialaccount.
Installed 0 object(s) from 0 fixture(s)
akoumjian commented 10 years ago

I am not using a custom user model.

Migrating IS needed for my own models. I can of course set South to ignore allauth, but then if I choose to keep allauth up to date, I may be unable to do so.

pennersr commented 10 years ago

I am having trouble reproducing this. Could somebody send over a minimal tarball demonstrating the problem?

georgewhewell commented 10 years ago

I am also seeing this. FWIW removing django-extensions app seems to fix it.

@pennersr here is a tarball which reproduces the problem, although i suspect it is an issue with django-extensions. https://dl.dropboxusercontent.com/u/19815354/auth_bug.tar.gz

pennersr commented 10 years ago

Thanks @georgewhewell -- now I can reproduce it, though allauth is not the cause:

Related:

As suggested there, downgrading to South 0.8.2 fixes the problem.

jhgg commented 10 years ago

@pennersr, south 0.8.4 fixes this issue.

dh1tw commented 10 years ago

problem still exists here with South 0.8.4 and Django-Allauth 0.16.1 :-(

Here is my Traceback: Traceback (most recent call last): File "./manage.py", line 10, in execute_from_command_line(sys.argv) File "/Users/user/.virtualenvs/dxc-test/lib/python2.7/site-packages/django/core/management/init.py", line 399, in execute_from_command_line utility.execute() File "/Users/user/.virtualenvs/dxc-test/lib/python2.7/site-packages/django/core/management/init.py", line 392, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/Users/user/.virtualenvs/dxc-test/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv self.execute(_args, _options.dict) File "/Users/user/.virtualenvs/dxc-test/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute output = self.handle(_args, _options) File "/Users/user/.virtualenvs/dxc-test/lib/python2.7/site-packages/south/management/commands/convert_to_south.py", line 89, in handle delete_ghosts=options.get("delete_ghosts", False), File "/Users/user/.virtualenvs/dxc-test/lib/python2.7/site-packages/django/core/management/init.py", line 159, in call_command return klass.execute(_args, _defaults) File "/Users/user/.virtualenvs/dxc-test/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute output = self.handle(_args, _options) File "/Users/user/.virtualenvs/dxc-test/lib/python2.7/site-packages/south/management/commands/migrate.py", line 111, in handle ignore_ghosts = ignore_ghosts, File "/Users/user/.virtualenvs/dxc-test/lib/python2.7/site-packages/south/migration/init.py", line 173, in migrate_app Migrations.calculate_dependencies() File "/Users/user/.virtualenvs/dxc-test/lib/python2.7/site-packages/south/migration/base.py", line 229, in calculate_dependencies migration.calculate_dependencies() File "/Users/user/.virtualenvs/dxc-test/lib/python2.7/site-packages/south/migration/base.py", line 363, in calculate_dependencies for migration in self._get_dependency_objects("depends_on"): File "/Users/user/.virtualenvs/dxc-test/lib/python2.7/site-packages/south/migration/base.py", line 343, in _get_dependency_objects for app, name in getattr(self.migration_class(), attrname, []): File "/Users/user/.virtualenvs/dxc-test/lib/python2.7/site-packages/south/migration/base.py", line 315, in migration_class return self.migration().Migration File "/Users/user/.virtualenvs/dxc-test/lib/python2.7/site-packages/south/utils/init.py", line 62, in method value = function(self) File "/Users/user/.virtualenvs/dxc-test/lib/python2.7/site-packages/south/migration/base.py", line 306, in migration raise exceptions.BrokenMigration(self, sys.exc_info()) south.exceptions.BrokenMigration: While loading migration 'socialaccount:0001_initial': Traceback (most recent call last): File "/Users/user/.virtualenvs/dxc-test/lib/python2.7/site-packages/south/migration/base.py", line 302, in migration migration = import(full_name, {}, {}, ['Migration']) File "/Users/user/.virtualenvs/dxc-test/lib/python2.7/site-packages/allauth/socialaccount/migrations/0001_initial.py", line 11, in User = get_user_model() File "/Users/user/.virtualenvs/dxc-test/lib/python2.7/site-packages/django/contrib/auth/init.py", line 129, in get_user_model raise ImproperlyConfigured("AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL) ImproperlyConfigured: AUTH_USER_MODEL refers to model 'auth.User' that has not been installed

berserkia commented 10 years ago

I had the exact same error in production, any resolution?

phoenixwizard commented 10 years ago

problem still exists here with South 0.8.4 ... Any resolution?

Traceback (most recent call last): File "./manage.py", line 10, in execute_from_command_line(sys.argv) File "/home/vagrant/.virtualenvs/sliderule/local/lib/python2.7/site-packages/django/core/management/init.py", line 399, in execute_from_command_line utility.execute() File "/home/vagrant/.virtualenvs/sliderule/local/lib/python2.7/site-packages/django/core/management/init.py", line 392, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/vagrant/.virtualenvs/sliderule/local/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv self.execute(_args, _options.dict) File "/home/vagrant/.virtualenvs/sliderule/local/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute output = self.handle(_args, _options) File "/home/vagrant/.virtualenvs/sliderule/local/lib/python2.7/site-packages/south/management/commands/convert_to_south.py", line 89, in handle delete_ghosts=options.get("delete_ghosts", False), File "/home/vagrant/.virtualenvs/sliderule/local/lib/python2.7/site-packages/django/core/management/init.py", line 159, in call_command return klass.execute(_args, _defaults) File "/home/vagrant/.virtualenvs/sliderule/local/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute output = self.handle(_args, _options) File "/home/vagrant/.virtualenvs/sliderule/local/lib/python2.7/site-packages/south/management/commands/migrate.py", line 111, in handle ignore_ghosts = ignore_ghosts, File "/home/vagrant/.virtualenvs/sliderule/local/lib/python2.7/site-packages/south/migration/init.py", line 173, in migrate_app Migrations.calculate_dependencies() File "/home/vagrant/.virtualenvs/sliderule/local/lib/python2.7/site-packages/south/migration/base.py", line 229, in calculate_dependencies migration.calculate_dependencies() File "/home/vagrant/.virtualenvs/sliderule/local/lib/python2.7/site-packages/south/migration/base.py", line 363, in calculate_dependencies for migration in self._get_dependency_objects("depends_on"): File "/home/vagrant/.virtualenvs/sliderule/local/lib/python2.7/site-packages/south/migration/base.py", line 343, in _get_dependency_objects for app, name in getattr(self.migration_class(), attrname, []): File "/home/vagrant/.virtualenvs/sliderule/local/lib/python2.7/site-packages/south/migration/base.py", line 315, in migration_class return self.migration().Migration File "/home/vagrant/.virtualenvs/sliderule/local/lib/python2.7/site-packages/south/utils/init.py", line 62, in method value = function(self) File "/home/vagrant/.virtualenvs/sliderule/local/lib/python2.7/site-packages/south/migration/base.py", line 306, in migration raise exceptions.BrokenMigration(self, sys.exc_info()) south.exceptions.BrokenMigration: While loading migration 'socialaccount:0001_initial': Traceback (most recent call last): File "/home/vagrant/.virtualenvs/sliderule/local/lib/python2.7/site-packages/south/migration/base.py", line 302, in migration migration = import(full_name, {}, {}, ['Migration']) File "/vagrant/backend/new_sliderule/learned/allauth/socialaccount/migrations/0001_initial.py", line 11, in User = get_user_model() File "/home/vagrant/.virtualenvs/sliderule/local/lib/python2.7/site-packages/django/contrib/auth/init.py", line 129, in get_user_model raise ImproperlyConfigured("AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL) ImproperlyConfigured: AUTH_USER_MODEL refers to model 'auth.User' that has not been installed

lddubeau commented 10 years ago

@dh1tw @phoenixwizard The problem you guys ran into looks the same but I don't think it is the same as what the OP reported. The OP was reporting an issue with the migrate command whereas you are running into an issue with the convert_to_south command, which performs some manipulation of the app cache. I ran into the same issue you guys ran into. I'm running Django 1.6.5, South 0.8.4 and django-allauth 0.15.0. After inspecting the convert_to_south.py file, I figured that the following two commands would essentially do the same thing that ./manage.py convert_to_south [app] does:

./manage.py schemamigration [app] --initial
./manage.py migrate [app] --fake

When I run these commands, I don't run into any problem so I'm guessing that convert_to_south is messing up the app cache somehow. The problem probably has to do with these lines in South's code (in convert_to_south.py) which are executed between the invocations of schemamigration and migrate:

    # Now, we need to re-clean and sanitise appcache
    hacks.clear_app_cache()
    hacks.repopulate_app_cache()

    # And also clear our cached Migration classes
    Migrations._clear_cache()
phoenixwizard commented 10 years ago

@lddubeau any solution you can think of?

lddubeau commented 10 years ago

@phoenixwizard No solution other than the workaround I've mentioned in my previous post (i.e. run schemamigration and migrate in two steps manually). It does not fix the problem in South's code but it at least allows someone who runs into the issue to move forward with their work.

Miserlou commented 9 years ago

I had this problem and found that it was actually related to a missing import. Not sure if this is related, but could be helpful to any person searching for a fix.

jhagege commented 9 years ago

Any solution to this issue? Thanks

ratijas commented 5 years ago

aaaaaaaaaand it still happens.

ahmed-almawardy commented 3 years ago

till now!

soham-padia commented 2 years ago

bruh whyyyyyy

Salmanulhamdan commented 1 year ago

any body have solution

siavashoh commented 1 year ago

I also got this error and solved it by renaming the file name of the model. I don't know why. I test it several times and reverted it to the old name and got that error. then after renaming, it was solved

for more information, my model's file's name was "invite"