django在models.py中创建一个类,写入对应数据表对应的字段,在tool—Run manage.py task执行
makemigrations Mynewsite
再执行:
migrate Mynewsite
查看下数据表:
这时就可以在数据库中查到对应得数据表,但是这个时候需要再增加某些字段,就需要修改下models.py,如图
然后在tool—Run manage.py task执行
makemigrations Mynewsite
出现:
You are trying to add a non-nullable field 'message' to usermessage 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:
这时候需要message新增一个default的值
然后重新执行
makemigrations Mynewsite
出现:
Migrations for 'Mynewsite':
Mynewsite\migrations\0002_usermessage_message.py:
- Add field message to usermessage
再执行:
migrate Mynewsite
查看数据库message新增进去了