7👍
You forgot to actually update/migrate your database. This should happen upon initial syncdb
, and ideally via a proper database migration using django-south in Django version up to 1.6, or using the new Django migrations framework to be released in Django 1.7+.
For development purposes you can reset your DB (this will delete all data!) and recreate:
$ ./manage.py reset appname
$ ./manage.py syncdb
If you’re using South migrations:
$ ./manage.py schemamigration --auto appname
$ ./manage.py syncdb --migrate
2👍
I guess the problem is solved by now, but I ran into the same issue last week. While the answers regarding migrations are correct, it is worth noting that URLField
is based on CharField
. This means that the length limitations of CharField
also apply to URLField
, no matter what max_length
you define (see also https://docs.djangoproject.com/en/3.0/ref/models/fields/#urlfield – this answer referred to Django 1.9 which was the latest release when I initially wrote it and this is still the same for Django 3.0 in 2020).
Somewhat unrelated to the original question, but a possible problem even if you use the default max_length=200
is how MySQL currently deals with UTF-8 text. You can find out more about this VARCHAR()
indexing issue on https://serversforhackers.com/mysql-utf8-and-indexing or in the MySQL 5.7 manual on http://dev.mysql.com/doc/refman/5.7/en/charset-unicode-upgrading.html.
A possible solution for having a longer URLField
has been posted in Advantages to using URLField over TextField? – simply define a Textfield with the relevant validator.