欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 高考 > django如何更新数据库字段并与数据库保持同步?

django如何更新数据库字段并与数据库保持同步?

2024/10/24 20:20:01 来源:https://blog.csdn.net/weixin_46923615/article/details/140992824  浏览:    关键词:django如何更新数据库字段并与数据库保持同步?

关键步骤:

  1. 第一步: 执行:python manage.py makemigrations  你的项目名称
  2. 第二步:它会提示你选1还是2,这里因为添加字段,所以选1
  3. 第三步:出现>>>这个,直接输入这个''
  4. 第四步: 执行:python manage.py migrate
  5. 第五步:运行项目:python manage.py runserver  本机ip:8000

(.venv) PS D:\python_workpace\django_xitong_shezhi\pythonProject\myproject> python manage.py makemigrations  myproject
It is impossible to add a non-nullable field 'title_field22' to yingyongguanli without specifying a default. This is because the database needs something to populate existing rows.
Please select a fix:2) Quit and manually define a default value in models.py.
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.
>>> ‘’
Invalid input: invalid character '‘' (U+2018) (<string>, line 1)
>>> ''
Migrations for 'myproject':myproject\migrations\0002_yingyongguanli_title_field22.py- Add field title_field22 to yingyongguanli
(.venv) PS D:\python_workpace\django_xitong_shezhi\pythonProject\myproject> python manage.py migrate
Operations to perform:Apply all migrations: admin, auth, contenttypes, myproject, sessions
Running migrations:Applying myproject.0002_yingyongguanli_title_field22... OK
(.venv) PS D:\python_workpace\django_xitong_shezhi\pythonProject\myproject> python manage.py runserver  10.0.4.144:8000
Watching for file changes with StatReloader
Performing system checks...System check identified no issues (0 silenced).
August 07, 2024 - 15:05:12
Django version 5.0.6, using settings 'myproject.settings'
Starting development server at http://10.0.4.144:8000/
Quit the server with CTRL-BREAK.

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com