我们在学习框架的时候不可避免的要用到数据库,所以框架主要就是和数据库打交道,但是在进行数据迁移的时候难免会出现一点小BUG,此以Django为例,进行二次数据库迁移的时候可能会出现迁移文件已经存在,迁移信息冲突的问题吗,或者是数据库表已经存在,都会报错。我们今天讲的就是迁移信息冲突的问题。
You are trying to add a non-nullable field 'u_c' to courses 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: ^CTraceback (most recent call last):
报了这个错我们怎么办呢?不要急,我们下面举个例子来说明一下怎么解决。(不过要是删库的话也不是不可以,强烈建议不要删库,道理应该懂的)
举个例子吧:第一步:我们先创建两个表,分别是Users和courses
代码如下:
from django.db import models
# Create your models here.
class Users(models.Model):
u_name = models.CharField(max_length=32)
u_age = models.CharField(max_