django错误集合

1报错:

You are trying to add a non-nullable field ‘ban’ to user without a default; we can’t do that (the database needs something to populate existing rows).
Please select a fix:

  1. Provide a one-off default now (will be set on all existing rows with a null value for this column)
  2. Quit, and let me add a default in models.py
    Select an option:

解决办法:将新添加的数据全部增加默认值
如:secondjiqiang = models.IntegerField(default=1)

2报错:
执行manage.py makemigrations 未提示错误信息,但manage.py migrate时进行同步数据库时出现问题;django.db.utils.OperationalError: (1050, "Table ‘表名’ already exists)错误信息
解决方法:python manage.py migrate myapp --fake

3报错python manage.py migrate时,系统提示
No migrations to apply.
原因:可能是之前执行过python manage.py migrate --fake
–fake 的含义是不执行该迁移脚本但是标记该脚本已经被执行过。导致之后无法正常进行迁移。
解决方案: 1)进入 mysql python manage.py dbshell
2)执行 SELECT * FROM django_migrations
django_migrations显示的是已经执行过migrate的py文件,打开后发现将要执行的迁移脚本的 id 已经添加在表中了,说明已经执行过 migrate了,需 将其删除
3)将其删除即可 delete from django_migrations where id=**;
4)退出mysql quit
5)重新执行 python manage.py migrate

你可能感兴趣的:(django错误集合)