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