1
应用迁移时出现错误django.db.migrations.graph.CircularDependencyError
。值得注意的是,我从一个空的数据库开始。Django循环依赖
我也设法归结到导致错误的类,这似乎是OAuthAccessToken
。
class OAuthAccessToken(Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, related_name='oauth_access_tokens',
help_text=_('User'))
provider = models.ForeignKey(Provider, related_name='oauth_access_tokens',
help_text=_('OAuth provider'))
token = fields.SafeRandomField(max_length=32,
help_text=_('Access token'))
上面的代码只有在注释provider
声明时才有效。 Provider
类来自allaccess框架。下面是它的声明:其他
@python_2_unicode_compatible
class Provider(models.Model):
"Configuration for OAuth provider."
name = models.CharField(max_length=50, unique=True)
request_token_url = models.CharField(blank=True, max_length=255)
authorization_url = models.CharField(max_length=255)
access_token_url = models.CharField(max_length=255)
profile_url = models.CharField(max_length=255)
consumer_key = EncryptedField(blank=True, null=True, default=None)
consumer_secret = EncryptedField(blank=True, null=True, default=None)
一种方法对我来说,使代码工作是,如果我从我的设置文件删除AUTH_USER_MODEL = 'api.User'
,在这种情况下,第一个代码示例工程。
的事情是,我检查了迁移,并发现这一点:
migrations.CreateModel(
name='OAuthAccessToken',
fields=[
('uid', rest.fields.IDField(default=rest.fields.GenerateID(15, b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), max_length=15, serialize=False, primary_key=True, help_text='Server generated public unique ID')),
('creation_date', models.DateTimeField(help_text='Creation date', auto_now_add=True)),
('last_update', models.DateTimeField(help_text='Last update', auto_now=True)),
('token', rest.fields.SafeRandomField(default=rest.fields.GenerateID(32, b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), help_text='Access token', max_length=32)),
('provider', models.ForeignKey(related_name='oauth_access_tokens', to='allaccess.Provider', help_text='OAuth provider')),
('user', models.OneToOneField(related_name='oauth_access_tokens', to=settings.AUTH_USER_MODEL, help_text='User')),
],
options={
'abstract': False,
},
bases=(models.Model,),
),
但我没有看到其中圆形依赖性。
编辑:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.7/site-packages/django/core/management/commands/migrate.py", line 106, in handle
plan = executor.migration_plan(targets)
File "/Library/Python/2.7/site-packages/django/db/migrations/executor.py", line 49, in migration_plan
for migration in self.loader.graph.forwards_plan(target):
File "/Library/Python/2.7/site-packages/django/db/migrations/graph.py", line 55, in forwards_plan
return self.dfs(node, lambda x: self.dependencies.get(x, set()))
File "/Library/Python/2.7/site-packages/django/db/migrations/graph.py", line 105, in dfs
raise CircularDependencyError()
django.db.migrations.graph.CircularDependencyError
编辑:更新使用Django 1.7.7
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.7/site-packages/django/core/management/commands/migrate.py", line 106, in handle
plan = executor.migration_plan(targets)
File "/Library/Python/2.7/site-packages/django/db/migrations/executor.py", line 54, in migration_plan
for migration in self.loader.graph.forwards_plan(target):
File "/Library/Python/2.7/site-packages/django/db/migrations/graph.py", line 60, in forwards_plan
return self.dfs(node, lambda x: self.dependencies.get(x, set()))
File "/Library/Python/2.7/site-packages/django/db/migrations/graph.py", line 124, in dfs
self.ensure_not_cyclic(start, get_children)
File "/Library/Python/2.7/site-packages/django/db/migrations/graph.py", line 112, in ensure_not_cyclic
raise CircularDependencyError(", ".join("%s.%s" % n for n in cycle))
django.db.migrations.graph.CircularDependencyError: api.0001_initial, allaccess.0001_initial
你能发布完整的错误信息吗?有关您的迁移的更多信息也会有所帮助,特别是在依赖性方面。 – knbk 2015-04-05 18:39:03
@mu无尽管在不同的车型上,所以这没问题。 – knbk 2015-04-05 18:39:29
@mu无我已经尝试了不同的名字,没有效果 – 2015-04-05 18:42:56