网站首页 文章专栏 Django不能创建数据表
在运行
python3 manage.py makemigrations
python3 manage.py migrate
之后,返回
Operations to perform:
Apply all migrations: admin, auth, authtoken, contenttypes, sessions, sites, viewer
Running migrations:
Applying viewer.0004_todo... OK
看着一切正常,但是数据库就是无法创建todo表。
后来发现在models.py
中的Meta
属性需要为True
,完整的数据表为
class Todo(models.Model):
gen_time = models.DateTimeField(blank=True, null=True)
update_time = models.DateTimeField(blank=True, null=True)
finish_time = models.DateTimeField(blank=True, null=True)
properties = models.TextField(blank=True, null=True)
content = models.TextField(blank=True, null=True)
status = models.IntegerField(blank=True, null=True)
father = models.IntegerField(blank=True, null=True)
class Meta:
## 这里需要为True
managed = True
db_table = 'todo'
因为我其他的数据表都是自己导入的,所以填了False,今天这个照葫芦画瓢结果搞错了,浪费了不少时间。
python3 manage.py dbshell
删除数据库中django_migrations
中的对应记录可以重新应用migrate
删除 app
文件夹下的 migrations
文件夹中的 对应文件可以重新执行python3 manage.py makemigrations