2013-05-20 72 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