在嘗試批量加載我從一個從MS-Access轉換到Google App Engine的django項目中的一些遺留數據(通過django-nonrel)時,我想我試圖插入數據時遇到了一堵磚牆一個具有0(零)值的主鍵。我的很多數據都有零個主鍵,並且主鍵爲零的行被視爲特殊的並被許多外鍵引用(因此很難修復所有對行的引用)。谷歌應用程序引擎上的django-nonrel:PrimaryKey字段的值是否爲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應用引擎中的整數主鍵字段中的零值?
謝謝!