繁体   English   中英

django中的自定义用户引发了ValueError

[英]Custom user in django raises ValueError

即使这个简单的例子也会抛出一个ValueError: Dependency on app with no migrations: myApp python manage.py syncdb期间的ValueError: Dependency on app with no migrations: myApp

对myApp / models.py

from django.contrib.auth.models import AbstractUser

class User(AbstractUser):
    pass

settings.py

AUTH_USER_MODEL = 'myApp.User'

在django中运行./manage syncdb == 1.6.5 <<有效

Creating tables ...

在django中运行./manage syncdb == 1.7 <<中断

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/bdhammel/Documents/web_development/tutorials/python_social_auth/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/Users/bdhammel/Documents/web_development/tutorials/python_social_auth/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/bdhammel/Documents/web_development/tutorials/python_social_auth/env/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Users/bdhammel/Documents/web_development/tutorials/python_social_auth/env/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/Users/bdhammel/Documents/web_development/tutorials/python_social_auth/env/lib/python2.7/site-packages/django/core/management/base.py", line 533, in handle
    return self.handle_noargs(**options)
  File "/Users/bdhammel/Documents/web_development/tutorials/python_social_auth/env/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 27, in handle_noargs
    call_command("migrate", **options)
  File "/Users/bdhammel/Documents/web_development/tutorials/python_social_auth/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 115, in call_command
    return klass.execute(*args, **defaults)
  File "/Users/bdhammel/Documents/web_development/tutorials/python_social_auth/env/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/Users/bdhammel/Documents/web_development/tutorials/python_social_auth/env/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 63, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "/Users/bdhammel/Documents/web_development/tutorials/python_social_auth/env/lib/python2.7/site-packages/django/db/migrations/executor.py", line 17, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/Users/bdhammel/Documents/web_development/tutorials/python_social_auth/env/lib/python2.7/site-packages/django/db/migrations/loader.py", line 48, in __init__
    self.build_graph()
  File "/Users/bdhammel/Documents/web_development/tutorials/python_social_auth/env/lib/python2.7/site-packages/django/db/migrations/loader.py", line 239, in build_graph
    parent = self.check_key(parent, key[0])
  File "/Users/bdhammel/Documents/web_development/tutorials/python_social_auth/env/lib/python2.7/site-packages/django/db/migrations/loader.py", line 163, in check_key
    raise ValueError("Dependency on app with no migrations: %s" % key[0])
ValueError: Dependency on app with no migrations: myApp

我还没有在1.7的文档中找到任何说明这应该以1.6的方式完成的任何内容。 它确实看起来像其他人也有这个问题 ,但是因为运行./manage.py migrate --list

有没有遇到过这个?

我想我在错误的地方寻找答案:

我通过运行: ./manage.py makemigrations myApp解决了这个问题

(env)Bens-MacBook-Pro:social_auth bdhammel$ ./manage.py makemigrations myApp
Migrations for 'myApp':
  0001_initial.py:
    - Create model User
(env)Bens-MacBook-Pro:social_auth bdhammel$ python manage.py syncdb
Operations to perform:
  Apply all migrations: sessions, admin, myApp, auth, default, contenttypes
Running migrations:
  Applying contenttypes.0001_initial... FAKED
  Applying auth.0001_initial... FAKED
  Applying app.0001_initial... FAKED
  Applying admin.0001_initial... FAKED
  Applying default.0001_initial... FAKED
  Applying sessions.0001_initial... FAKED

You have installed Django's auth system, and don't have any superusers defined.
Would you like to create one now? (yes/no): yes

通过https://docs.djangoproject.com/en/1.7/topics/migrations/#s-custom-fields

编辑
我应该使用python manage.py migrate而不是python manage.py syncdb

https://docs.djangoproject.com/en/1.8/releases/1.7/#schema-migrations

syncdb已被弃用,并由migrate替换。 别担心 - 对syncdb的调用仍然可以像以前一样工作。

  1. 删除每个应用中的迁移文件夹
  2. 删除表django_migrations
  3. 运行python3 manage.py makemigrations app1
  4. 运行python3 manage.py makemigrations app2

manage.py runserver现在应该像魅力一样工作

当我将应用程序移动到一个干净的新项目而不删除迁移时,这种情况发生在我身上。 如果您不关心迁移并从头开始创建项目,请考虑从这些应用程序中删除迁移。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM