Question

I created a model from an existing PostgreSql database using inspectdb, when I try to do a syncdb,in order to generate the authorization tables, it generates the following error:

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

So I put the max_length=255 to all CharFields but it doesn't work neither with that. Django version is 1.5.1. Anyone have an idea how to fix this?

Was it helpful?

Solution

Currently inspectdb doesn't set max_length for PostgreSQL char fields without specified length. FYI, quote from postgreSQL docs:

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.

But, Django doesn't allow to define CharFields without max_length parameter. There is an open ticket for it.

This django snippet provides a custom CharField without length limit - should pass all django's validation.

Also, switching to TextField could help too.

Hope that helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top