问题1:django.db.utils.OperationalError: table "zuoy_nav" already exists
1、python manage.py showmigrations
(显示出Django项目中的所有migrations文件及其状态,[x] 代表已经执行完毕的migrations文件, []表示未执行或执行失败的文件。)
显示:
zuoy
[ ] 0001_initial
2、python manage.py migrate zuoy
没起作用(郁闷。。。)
3、直接修改文件:
C:\Users\Administrator\PycharmProjects\zyday18\zuoy\migrations\0001_initial.py
4、注释掉 already exists table的相关信息,例如:
# migrations.CreateModel(
# name='Article',
# fields=[
# ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
# ('title', models.CharField(max_length=20, verbose_name='文章名称')),
# ('content', models.TextField(null=True, verbose_name='文章内容')),
# ('img', models.ImageField(null=True, upload_to='article_img', verbose_name='文章图片')),
# ('is_delete', models.SmallIntegerField(default=1, verbose_name='是否被删除')),
# ('create_time', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
# ('update_time', models.DateTimeField(auto_now=True, verbose_name='修改时间')),
# ('nav', models.ForeignKey(db_constraint=False, on_delete=django.db.models.deletion.DO_NOTHING, to='zuoy.Nav', verbose_name='导航id')),
# ],
# options={
# 'db_table': 'article',
# },
# ),
5、再执行python manage.py migrate
table创建成功,sqlite3中可以看到该table。
执行python manage.py showmigrations ,显示:
zuoy
[X] 0001_initial
模板看起来是不是太过冰冷