Psycopg changing Model Fields at Git push?


#1

Hey everyone. So my app has a model field for price that was originally a charfield. When I added a sort by price option on the site the prices would come up in string order instead of numerical. Ex: for high to low an item that cost 9.99 is higher than an item priced at 84.99.

I changed the model field to decimal field and it seemed to have solved the issue locally. I pushed the app to Heroku and now the issue has popped up again. In trying to dig for an answer I’ve read that Psycopg can do that but I’m at a loss at where to go/what to look for to troubleshoot. Any ideas?


#2

Huh, that sounds confusing!

I’m sure you ran migrate locally… did you make sure to migrate on Heroku as well? :)


#3

I just did, and it says “no migrations to apply”.

Before that I erased all the local migrations to migrate locally again. Then pushed to Heroku. Other changes took effect but this one…still there.


#4

Ok i just inspected the database in postgres and for my model ‘price’ is a Charfield.


#5

Do you have data that you need to save in your database on Heroku? I worry that by nuking your migrations, you’re going to be in trouble with your production database (since you killed the “plans”) if you have data you need to save. :)

I chatted with someone, sounds like it’s more Django, not psycopg that’s having issues. Django doesn’t do very well with changing database types (going from Charfield to Decimal) — he recommends making changes like that in 3 steps:

  1. add new field
  2. copy data over
  3. delete old field

So, hopefully if you don’t have data to save, you can nuke your databases and start from scratch. If you have data that you need to save, you could try to export the data somehow and reimport after the database field types are correct.

Let me know if that helps!


#6

I a little data, but nothing major. I’ll give this a shot. Thanks!