Django的模型表新增字段


D:\envs\mtb>python manage.py makemigrations
It is impossible to add a non-nullable field 'password' to info without specifying a default. This is because the database needs something to populate existing row
s.
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 manually define a default value in models.py.
Select an option: 

在输入数据库迁移指令时,提示字段没有默认值,而且没有设置可以为空,会有提示
1)在终端输入默认值
2)自己创建

Select an option: 1
Please enter the default value as valid Python.
The datetime and django.utils.timezone modules are available, so it is possible to provide e.g. timezone.now as a value.
Type 'exit' to exit this prompt
>>> ''
It is impossible to add a non-nullable field 'username' to info without specifying a default. This is because the database needs something to populate existing row
s.

选择1,进入Python,输入一个完整的引号,中级不带空格

Migrations for 'base':
  apps\base\migrations\0002_remove_info_name_info_password_info_username.py
    - Remove field name from info
    - Add field password to info
    - Add field username to info

继续执行数据库迁移指令

D:\envs\mtb>python manage.py migrate
Operations to perform:
  Apply all migrations: base
Running migrations:
  Applying base.0002_remove_info_name_info_password_info_username... OK


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM