Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django max_length value for a character verying row

So I have this pre-existing database that I'm trying to connect to using Django and I've already introspected the database and I'm just cleaning up the models before actually doing anything, and I've run into a roadblock. One of the database tables has a row:

"name" character varying NOT NULL

and when I've run python manage.py syncdb, I get the following error:

app.artistname: "name": CharFields require a "max_length" attribute that is a positive integer.

So I went into models.py to find out what the problem is, and I see:

name = models.CharField(unique=True, max_length=-1)

So my question is, what value should I set max_length to if not even the definition in the database has a value set? Do I just set it to the maximum possible value?

like image 257
Gabe C. Avatar asked Apr 11 '12 03:04

Gabe C.


1 Answers

For a field of varying length, you can use a TextField instead of a CharField so you don't have to set a size.

Both varying length fields and TextFields are generally intended for large amounts of text.

like image 118
agf Avatar answered Sep 30 '22 10:09

agf