我已经创建了一个模型语言。我做了makemigrations
和migrate
部分。一切都很顺利。我在设置文件中注册了我的数据库。
当我点击管理页面上的语言表时,我得到了这个:
OperationalError at /admin/testdb/language/
no such table: testdb_language
Request Method: GET
Request URL: http://localhost:8000/admin/testdb/language/
Django Version: 1.9.5
Exception Type: OperationalError
Exception Value:
no such table: testdb_language
Exception Location: /Users/nep/Documents/Development/Private/testdjango/myvenv/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py in execute, line 323
Python Executable: /Users/nep/Documents/Development/Private/testdjango/myvenv/bin/python
Python Version: 3.5.1
Python Path:
['/Users/nep/Documents/Development/Private/testdjango',
'/Library/Frameworks/Python.framework/Versions/3.5/lib/python35.zip',
'/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5',
'/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/plat-darwin',
'/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/lib-dynload',
'/Users/nep/Documents/Development/Private/testdjango/myvenv/lib/python3.5/site-packages']
我的模型定义如下:
from django.db import models
class Oxn(models.Model):
objectId = models.CharField(max_length=100, unique=True)
name = models.CharField(max_length=100)
picture = models.CharField(max_length=200)
class Language(models.Model):
objectId = models.CharField(max_length=100, unique=True)
code = models.CharField(max_length=10)
language = models.CharField(max_length=100)
我没有看到问题所在。有人能帮助我吗?
编辑:
这是迁移的输出:
(myvenv) ➜ gins4udjango python manage.py showmigrations
admin
[X] 0001_initial
[X] 0002_logentry_remove_auto_add
auth
[X] 0001_initial
[X] 0002_alter_permission_name_max_length
[X] 0003_alter_user_email_max_length
[X] 0004_alter_user_username_opts
[X] 0005_alter_user_last_login_null
[X] 0006_require_contenttypes_0002
[X] 0007_alter_validators_add_error_messages
contenttypes
[X] 0001_initial
[X] 0002_remove_content_type_name
ginsdb
[X] 0001_initial
sessions
[X] 0001_initial
修改
来自迁移的0001_initial.py具有以下内容:
# -*- coding: utf-8 -*-
# Generated by Django 1.9.5 on 2016-04-29 14:51
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Country',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('objectId', models.CharField(max_length=100, unique=True)),
('name', models.CharField(max_length=100)),
],
),
migrations.CreateModel(
name='Gin',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('objectId', models.CharField(max_length=100, unique=True)),
('alcohol', models.FloatField(blank=True, default=None, null=True)),
('name', models.CharField(max_length=100)),
('picture', models.CharField(max_length=200)),
],
),
migrations.CreateModel(
name='GinLocal',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('objectId', models.CharField(max_length=100, unique=True)),
('origin', models.TextField()),
('serve', models.TextField()),
('aroma', models.TextField()),
('country', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ginsdb.Country', to_field='objectId')),
('gin', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ginsdb.Gin', to_field='objectId')),
],
),
migrations.CreateModel(
name='Language',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('objectId', models.CharField(max_length=100, unique=True)),
('code', models.CharField(max_length=10)),
('language', models.CharField(max_length=100)),
],
),
migrations.CreateModel(
name='Type',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('objectId', models.CharField(max_length=100, unique=True)),
('typeName', models.CharField(max_length=100)),
('language', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ginsdb.Language', to_field='objectId')),
],
),
migrations.AddField(
model_name='ginlocal',
name='language',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ginsdb.Language', to_field='objectId'),
),
migrations.AddField(
model_name='ginlocal',
name='types',
field=models.ManyToManyField(to='ginsdb.Type'),
),
migrations.AddField(
model_name='country',
name='language',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ginsdb.Language', to_field='objectId'),
),
]
答案 0 :(得分:3)
0001_initial
应用的ginsdb
迁移包含Language
模型,因此应该在迁移时创建。
如果您仍在开发并且没有任何重要数据,那么最简单的方法是删除数据库,然后重新运行新数据库的迁移。只需删除sqlite数据库文件,然后重新运行./manage.py migrate
。
如果您需要保留数据库,那么您可以尝试手动创建模型,但这将更加棘手。您可以通过运行以下命令查看所需的SQL来创建模型:
./manage.py sqlmigrate ginsdb 0001_initial