作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在数据库中有一个现有模型。我想用一个 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/
我想创建一个表,然后创建一个应该插入到该表中的数据列表。南方有能力做这样的事吗?如果是这样,您是否有任何引用可以告诉我如何做到这一点? 我希望能够做到这一点,因为在这一点上,获得“完全”相同数据的唯一
我是一名优秀的程序员,十分优秀!