Skip to content
Advertisement

Django migrate ProgrammingError: syntax error at or near “”

I’m learning django (1.9.2) on a practice web site and a postgresql database with psycopg2. I defined a model with a certain attribute “preview” and later deleted the attribute entirely. Despite having removed it, django seems to be referencing that old definition perhaps from a cache or something. The makemigrations command seems to work fine, reflecting every change that I make to the model definition, but once I run the migrate command, then this error pops up.

JavaScript

The database tables are empty, so I suspect that deleting the database and making a new one might fix the issue for now, but I’d like a more concrete solution in case it happens again in the future where deleting the database is not an option.

Here’s what the model definition looks like.

JavaScript

There’s no “preview” attribute anymore, yet django doesn’t seem to get that.

Edit: Here’s the definition for the preview field

JavaScript

It produced an error saying it couldn’t be null, so I entered a one time default value "news preview". I assume the default value is for existing entries. At the time there were about 5 test entries. Just read on another post that the quotes I used when entering the one time default value was the likely cause of the problem. Something about psycopg2 not liking quotes on values?… It was a string value, so I thought I needed quotes.

Anyways, so now that I’ve cleared out the preview field, how do I make django forget it was ever there?

Advertisement

Answer

Going off the other comments and my own experience . . . when you get this error, go into your migrations folder and delete everything except the __init__.py. You can even delete the __pycache__ folder. Then run makemigrations and migrate again. I think that should fix the problem.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement