Django 转移到 PostgreSQL 无法导入固定装置,说明数据太长

标签 django json sqlite postgresql fixtures

我正在从使用 SQLite3 切换到 PostgreSQL,并希望我可以使用我一直用来填充 SQLite3 的固定装置来填充数据库。但是,我收到了这些错误:

$ python manage.py loaddata fixtures/core.json fixtures/auth.json

Installing json fixture 'fixtures/core' from absolute path.
Problem installing fixture 'fixtures/core.json': Traceback (most recent call last):
  File "/home/mvid/webapps/nihl/nihlapp/django/core/management/commands/loaddata.py", line 153, in handle
    obj.save()
  File "/home/mvid/webapps/nihl/nihlapp/django/core/serializers/base.py", line 163, in save
    models.Model.save_base(self.object, raw=True)
  File "/home/mvid/webapps/nihl/nihlapp/django/db/models/base.py", line 495, in save_base
    result = manager._insert(values, return_id=update_pk)
  File "/home/mvid/webapps/nihl/nihlapp/django/db/models/manager.py", line 177, in _insert
    return insert_query(self.model, values, **kwargs)
  File "/home/mvid/webapps/nihl/nihlapp/django/db/models/query.py", line 1087, in insert_query
    return query.execute_sql(return_id)
  File "/home/mvid/webapps/nihl/nihlapp/django/db/models/sql/subqueries.py", line 320, in execute_sql
    cursor = super(InsertQuery, self).execute_sql(None)
  File "/home/mvid/webapps/nihl/nihlapp/django/db/models/sql/query.py", line 2369, in execute_sql
    cursor.execute(sql, params)
  File "/home/mvid/webapps/nihl/nihlapp/django/db/backends/util.py", line 19, in execute
    return self.cursor.execute(sql, params)
DataError: value too long for type character varying(30)

我从来没有得到任何数据长度错误,我也没有改变数据库切换之间的模型。 PostgreSQL 正在运行 utf8。有没有办法准确查看它在哪些 json 值上失败,以便我可以更新相应的模型?知道为什么这些值在 SQLite 中有效但在 PostgreSQL 中失败吗?

最佳答案

Sqlite 不强制 varchar(n) 的长度。来自 sqlite 常见问题解答:

http://www.sqlite.org/faq.html#q9

关于Django 转移到 PostgreSQL 无法导入固定装置,说明数据太长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2377077/

相关文章:

javascript - 如何在django中的python函数处理过程中显示动画图标?

python - Django 管理员 : __str__ returned non-string (type int)

json - 从 JSON 文件保存和加载 TableView ?

javascript - 创建具有 3 个属性的 json 文件

java - 在 SQLiteDatabase 中存储一个具有 List<Object> 和字符串的对象

sqlite - 如果不存在,请将列添加到 sqlite db - flex/air sqlite?

Django 在 API 中,如 + reactjs。如何生成 csrf token

python - 如何更改 Django 中的模板框架?

javascript - 访问多个 JSON 数组中的元素

android - 如何将数据插入android中的SQLite数据库?