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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值