【发布时间】:2016-03-02 17:57:51
【问题描述】:
在我尝试从管理站点访问这些模型之前,我的应用程序中的一切似乎都运行顺利,那时我收到了我提到的错误,我安装了 Allauth 并进行了所有必要的迁移,但我一直得到相同的结果不管我做什么都会出错。
有什么想法吗?
以下是模型:
class Cuentas(models.Model):
idCuenta = models.AutoField(primary_key=True, null=False, max_length=15)
user = models.OneToOneField(User)
Saldo = models.CharField(max_length=50)
class Meta:
managed = False
db_table = 'cuentas'
class Depositos(models.Model):
idDeposito = models.AutoField(primary_key=True, null=False, max_length=15)
idCuenta = models.ForeignKey(Cuentas)
Tipo = models.CharField(max_length=200)
Monto = models.CharField(max_length=50)
Fecha = models.DateField()
class Meta:
managed = False
db_table = 'deposits'
追溯:
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/admin/options.py" in wrapper
583. return self.admin_site.admin_view(view)(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in _wrapped_view
105. response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
52. response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/admin/sites.py" in inner
206. return view(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in _wrapper
29. return bound_func(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in _wrapped_view
105. response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in bound_func
25. return func.__get__(self, type(self))(*args2, **kwargs2)
File "/Library/Python/2.7/site-packages/django/contrib/admin/options.py" in changelist_view
1485. self.list_max_show_all, self.list_editable, self)
File "/Library/Python/2.7/site-packages/django/contrib/admin/views/main.py" in __init__
110. self.get_results(request)
File "/Library/Python/2.7/site-packages/django/contrib/admin/views/main.py" in get_results
219. result_count = paginator.count
File "/Library/Python/2.7/site-packages/django/core/paginator.py" in _get_count
72. self._count = self.object_list.count()
File "/Library/Python/2.7/site-packages/django/db/models/query.py" in count
338. return self.query.get_count(using=self.db)
File "/Library/Python/2.7/site-packages/django/db/models/sql/query.py" in get_count
436. number = obj.get_aggregation(using=using)[None]
File "/Library/Python/2.7/site-packages/django/db/models/sql/query.py" in get_aggregation
402. result = query.get_compiler(using).execute_sql(SINGLE)
File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
786. cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/utils.py" in execute
81. return super(CursorDebugWrapper, self).execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/utils.py" in execute
65. return self.cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/utils.py" in __exit__
94. six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Library/Python/2.7/site-packages/django/db/backends/utils.py" in execute
65. return self.cursor.execute(sql, params)
Exception Type: ProgrammingError at /admin/DraftFantasy/cuentas/
Exception Value: relation "cuentas" does not exist
LINE 1: SELECT COUNT(*) FROM "cuentas"
这是创建两个模型的初始迁移中的代码
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Cuentas',
fields=[
('idCuenta', models.AutoField(max_length=15, serialize=False, primary_key=True)),
('Saldo', models.CharField(max_length=50)),
('user', models.OneToOneField(to=settings.AUTH_USER_MODEL)),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='Depositos',
fields=[
('idDeposito', models.AutoField(max_length=15, serialize=False, primary_key=True)),
('Tipo', models.CharField(max_length=200)),
('Monto', models.CharField(max_length=50)),
('Fecha', models.DateField()),
('idCuenta', models.ForeignKey(to='DraftFantasy.Cuentas')),
],
options={
},
bases=(models.Model,),
),
谢谢!
【问题讨论】:
-
我能看到完整的回溯吗?
-
如果你有
managed = False,那么 Django 不会为这些模型创建任何迁移,你必须自己创建它们。 -
我已经编辑了问题以包含完整的回溯,正如我所提到的,我已经创建并运行了所有必要的迁移
-
你确定你有一个创建模型的迁移者吗?正如我之前所说,Django 不会为具有
managed=False的模型创建迁移。请显示您认为创建模型的迁移,以及./manage.py showmigrations的输出。 -
我已经添加了初始迁移中创建模型的代码
标签: django django-models