在Django灯具中指定ManyToMany字段

时间:2011-11-19 22:49:06

标签: django many-to-many fixtures

有关灯具的文档说明您可以使用主键的int值指定自然键。例如:

{
"pk": 1,
"model": "store.book",
"fields": {
    "name": "Mostly Harmless",
    "author": 42
}
}

然而,它没有说如何引用多种语言。我尝试过使用数组:

{
"pk": 1,
"model": "store.book",
"fields": {
    "name": "Mostly Harmless",
    "author": [42,43,44]
}
}

我编写脚本以生成fixture的方式,有时阵列中只有一个主键:

{
"pk": 1,
"model": "store.book",
"fields": {
    "name": "Mostly Harmless",
    "author": [42]
}
}

运行manage.py loaddata fixture.json时出现以下错误:

Problem installing fixture 'fixtures/NCT00109798.json': Traceback (most recent call last):

File "/usr/lib/python2.6/site-packages/django/core/management/commands/loaddata.py", line 174, in handle
obj.save(using=using)

File "/usr/lib/python2.6/site-packages/django/core/serializers/base.py", line 165, in save
models.Model.save_base(self.object, using=using, raw=True)

File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 549, in save_base
result = manager._insert(values, return_id=update_pk, using=using)

File "/usr/lib/python2.6/site-packages/django/db/models/manager.py", line 195, in _insert
return insert_query(self.model, values, **kwargs)

File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 1518, in    insert_query
return query.get_compiler(using=using).execute_sql(return_id)

File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 788, in execute_sql
cursor = super(SQLInsertCompiler, self).execute_sql(None)

File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 732, in execute_sql
cursor.execute(sql, params)

File "/usr/lib/python2.6/site-packages/django/db/backends/util.py", line 15, in execute
return self.cursor.execute(sql, params)

File "/usr/lib/python2.6/site-packages/django/db/backends/mysql/base.py", line 86, in execute
return self.cursor.execute(query, args)

File "/usr/lib64/python2.6/site-packages/MySQLdb/cursors.py", line 175, in execute
if not self._defer_warnings: self._warning_check()

File "/usr/lib64/python2.6/site-packages/MySQLdb/cursors.py", line 89, in _warning_check
warn(w[-1], self.Warning, 3)

Warning: Data truncated for column 'keyword' at row 1

有没有其他方法可以使用灯具来指定这种关系?

0 个答案:

没有答案