gpt4 book ai didi

python - 添加 hstore 字段后如何创建迁移? (django-hstore 与南方)

转载 作者:行者123 更新时间:2023-11-29 13:05:04 24 4
gpt4 key购买 nike

我在数据库中有一个现有模型。我想用一个 hstore 字段来增强它。我安装了 hstore Postgres 扩展,django-hstore 应用程序,更改了 django 项目中的适当设置:

SOUTH_DATABASE_ADAPTERS = {'default': 'south.db.postgresql_psycopg2'}
DATABASES = {
'default': {
'ENGINE': 'django_hstore.postgresql_psycopg2',
...

我检查过 django 应用程序是否适用于新设置——确实如此。所以我将新字段添加到其中一个模型中:

data = hstore.DictionaryField(db_index=True)

下一步:数据库迁移。我迷路了。尝试为新字段创建迁移时,我得到以下信息:

The field 'Project.data' does not have a default specified, yet is NOT NULL.
Since you are adding this field, you MUST specify a default
value to use for existing rows. Would you like to:
1. Quit now, and add a default to the field in models.py
2. Specify a one-off value to use for existing columns now

我在这里做什么?我错过了什么?我没有在任何与 django-hstore 相关的文章中找到任何对默认值(或 null=True)的引用。

最佳答案

此消息通常在 South 尝试更新数据库中的模型并在您尝试修改的表中找到现有行时出现。为了继续并在数据库上创建新字段,您必须为要迁移的表的现有行指定一个值。我通常做的是,如果是开发阶段,我会选择选项 2 并将值设置为 0、{} 空字典,甚至 NULL,具体取决于字段类型。

关于python - 添加 hstore 字段后如何创建迁移? (django-hstore 与南方),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15908434/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com