我在数据库中有一个现有的模型。我想用一个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)的引用。
发布于 2013-04-10 02:24:35
当South尝试更新数据库上的模型,并在表yo上找到正在尝试修改的现有行时,通常会出现此消息。为了继续并在数据库上创建新字段,您必须为要迁移的表的现有行指定一个值。我通常做的是,如果是开发阶段,我选择选项2,并根据字段类型将值设置为0,{}空dict,甚至NULL。
发布于 2013-07-13 01:47:23
如前所述,当你点击2时,你可以选择一个空字符串(""),也可以用它存储的方式填充字段:
? The field 'MyModel.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
? Please select a choice: 2
? Please enter Python code for your one-off default value.
? The datetime module is available, so you can do e.g. datetime.date.today()
>>> "foo=>bar,foo2=>bar2"https://stackoverflow.com/questions/15908434
复制相似问题