Konstantin Paulus
Konstantin Paulus

Reputation: 2195

Django Rename Column In Postgresql

I have messed up my migrations and need to rename a column in my database, is that possible? Im also using docker which means I can't use any graphical interface to change tables in my db. If changing the column name isn't possible, maybe I could drop the hole table as there is no data saved on that table yet. How can I do that ?

Upvotes: 0

Views: 737

Answers (2)

Shynras
Shynras

Reputation: 140

You can just rename the field in the model you defined in Django, and then run:

python manage.py makemigrations
python manage.py migrate

In any case, when you want to delete a table you can use the python shell:

python manage.py shell

And then:

from {name_of_your_app}.models import {name_of_your_model}
{name_of_your_model}.objects.all().delete()

Upvotes: 0

schillingt
schillingt

Reputation: 13731

Run python manage.py dbshell. Then you'll have a PostgreSQL shell open. From there you can run your postgres queries to rename a column to match your migrations.

Upvotes: 1

Related Questions