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

标签 python django postgresql django-south hstore

我在数据库中有一个现有模型。我想用一个 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/

相关文章:

ruby-on-rails - Rails 3 使用 activerecord 将外键与 id 列表进行比较

python - 一旦我在 django 中激活模型,为什么我不能直接在 postgresql pgAdmin UI 中查询它们?

python: 类错误 __main__.foo 实例位于 0x

python - 基于关闭年份条件 Python 添加和减去值

html - 如何通过django html按钮执行python代码?

python - 我可以提供生成的图像而不将它们存储在服务器端吗?

database - Postgres服务不断重启

python - 源代码生成

python - 在重复迭代期间更有效的洗牌

python - Django:快速检索 manyToMany 字段的 ID