在尝试从我从MS-Access转换为Google App Engine的django项目(通过django-nonrel)批量加载一些遗留数据时,我想我在尝试插入数据时遇到了障碍使用具有0(零)值的主键。我的许多数据都没有主键,主键为零的行被视为特殊键并被许多外键引用(从而很难用行修复所有对行的引用。
尝试插入时出现以下错误:
File "/Users/myuser/my_app/django/core/management/commands/loaddata.py", line 174, in handle
obj.save(using=using)
File "/Users/myuser/my_app/django/core/serializers/base.py", line 165, in save
models.Model.save_base(self.object, using=using, raw=True)
File "/Users/myuser/my_app/django/db/models/base.py", line 573, in save_base
result = manager._insert(values, return_id=update_pk, using=using)
File "/Users/myuser/my_app/django/db/models/manager.py", line 195, in _insert
return insert_query(self.model, values, **kwargs)
File "/Users/myuser/my_app/django/db/models/query.py", line 1438, in insert_query
return query.get_compiler(using=using).execute_sql(return_id)
File "/Users/myuser/my_app/dbindexer/compiler.py", line 38, in execute_sql
return super(SQLInsertCompiler, self).execute_sql(return_id=return_id)
File "/Users/myuser/my_app/djangotoolbox/db/basecompiler.py", line 370, in execute_sql
return self.insert(data, return_id=return_id)
File "/Users/myuser/my_app/djangoappengine/db/compiler.py", line 59, in _func
return func(*args, **kwargs)
File "/Users/myuser/my_app/djangoappengine/db/compiler.py", line 470, in insert
entity = Entity(self.query.get_meta().db_table, **kwds)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/datastore.py", line 784, in __init__
datastore_types.ValidateInteger(id, 'id')
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/datastore_types.py", line 195, in ValidateInteger
raise exception('%s must not be 0 (zero)' % name)
DatabaseError: id must not be 0 (zero)
从这个转储中你可以看到在GoogleAppEngine python api代码本身中引发了错误,而不是django-nonrel或djangoappengine代码。所以我的问题是,您是否可以设置为在Google应用引擎中的整数主键字段中设置零值?
谢谢!
答案 0 :(得分:0)
我有一个类似的问题从mysql迁移到谷歌应用引擎。如果不能使用0并且保留正数,则解决方案可以是将整数值设置为负数。我将主键从import设置为negative,并且可以通过不同的方式处理导入和普通gae数据。
答案 1 :(得分:0)
错误似乎很清楚:不,你不能将主(整数)键设置为0。