2013-05-20 71 views
0

我使用inspectdb,当我尝试做一个执行syncdb创建从现有的PostgreSQL数据库的模型,以产生授权表后工作,它会生成以下错误:Django的执行syncdb不调用inspectdb

CommandError: One or more models did not validate: 
db.t1: "ip": CharFields require a "max_length" attribute that is a positive integer. 

所以我把​​所有的CharFields,但它不起作用。 Django版本是1.5.1。 任何人有一个想法如何解决这个问题?

回答

1

当前inspectdb没有为没有指定长度的PostgreSQL char字段设置max_length。仅供参考,和PostgreSQL文档报价:

The notations varchar(n) and char(n) are aliases for character varying(n) and character(n), respectively. character without length specifier is equivalent to character(1). If character varying is used without length specifier, the type accepts strings of any size. The latter is a PostgreSQL extension.

但是,Django的doesn't allow定义CharFields没有max_length参数。它有一个open ticket

这个django snippet提供了一个自定义CharField没有长度限制 - 应通过所有django的验证。

此外,切换到TextField也可以提供帮助。

希望有所帮助。

+0

我将导出的models.py复制到错误的文件夹中,花了大约2个小时才意识到它。虽然,谢谢你的帮助:) – xplorer00

+0

当然,问你什么时候需要另一个有趣的童话故事:) – alecxe