Go Live with Django & Heroku
I was following Justin Mitchels blog post about Going Live with Django and Heroku
I need to populate the database with a significant amount of data and I’ve been using
python manage.py loaddata --format json arch2json_all.json
Installed 221994 object(s) from 1 fixture(s)
In development with sqlite3 this works great.
Switch to my production branch push things up to Heroku
$ git push heroku master
$ heroku run python manage.py makemigrations
$ heroku run python manage.py migrate
Run into problems when I try to load the fixture.
$ heroku run bash
$ python manage.py loaddata --format json arch2json_all.json
django.db.utils.DataError: Problem installing fixture '/app/items/fixtures/arch2json_all.json': Could not load items.Monolithic(pk=None): value too long for type character varying(1024)
Looking in the usual locations I find a couple potential answers.
https://stackoverflow.com/questions/9036102/databaseerror-value-too-long-for-type-character-varying100
Could it be a SlugField without predefined length ?
class Monolithic(models.Model):
slug = models.SlugField(max_length=512, default='page-slug', blank=True)
Nope.
There’s only 1 field in the model that is 1024 or larger and that’s the msg field. But there none of the msg fields are even close to 1024 in size!
class Monolithic(models.Model):
msg = models.CharField(max_length=1024, blank=True, null=True)
slug = models.SlugField(max_length=512, default='page-slug', blank=True)
So why does loaddata work on sqlite3 but not postgres?
$ heroku run python manage.py dbshell
=> \d items_monolithic
msg | character varying(1024) | | |
Change msg to a TextField
msg = models.TextField(blank=True, null=True)
And still getting the error!
django.db.utils.DataError: Problem installing fixture '/app/items/fixtures/arch2json_all.json': Could not load items.Monolithic(pk=None): value too long for type character varying(1024)
$ heroku restart
$ heroku pg:reset DATABASE
▸ WARNING: Destructive action
▸ postgresql-acute-48401 will lose all of its data
▸
▸ To proceed, type testing or re-run this command with
▸ --confirm testing
> testing
No need to change the DATABASE
$ heroku run python manage.py makemigrations
$ heroku run python manage.py migrate
$ heroku run bash
$ python manage.py loaddata --format json arch2json_all.json
Installed 221994 object(s) from 1 fixture(s)
Why did I have to reset the postgres database?
Why didn’t makemigrations and migrate fix things?
Leave me a comment below.
Comments