>cd C:\xampp\cgi-bin\djangoPro #项目目录
>python manage.py makemigrations
>python manage.py migrate
1、执行:python manage.py makemigrations 报错,迁移失败
解决办法:添加默认值 default,重新进行迁移
class Author(models.Model):
name = models.CharField(max_length=50)
email = models.EmailField()
sex = models.CharField(max_length=10,default="男")
department = models.CharField(max_length=255, default="信息")
def __str__(self):
return self.name
2、已有表添加时间字段,报错如下
proApp.Author.puhlish_date: (fields.E160) The options auto_now, auto_now_add, and default are mutually exclusive. Only one of these options may be present.
选项auto_now, auto_now_add,default 互斥,只有有一个存在
解决办法:
class Author(models.Model):
name = models.CharField(max_length=50)
email = models.EmailField()
sex = models.CharField(max_length=10,default="男")
department = models.CharField(max_length=255, default="信息")
pthone = models.CharField(max_length=255,default="1")
publish_date = models.DateTimeField(u'发布时间', auto_now_add=True, editable=True, null=True)
def __str__(self):
return self.name
3、python manage.py migrate 迁移数据库失败
django.db.utils.InternalError: (1833, "Cannot change column 'id': used in a foreign key constraint 'proApp_author_book_book_id_b4feaab6_fk_proApp_book_id' of table 'python_sql.proapp_author_book'")
Applying proApp.0034_auto_20181228_1313...
解决办法:migrations 内文件全部删除即可