0

I just created a model named Carts and now I want to rename it to Cart only, how do I do it? I have tried doing this:

python manage.py makemigrations <app_name>

and then

python manage.py migrate

But its not reflecting the change in the database table: I am seeing the database as:

python manage.py sqlmigrate <app_name> 0001

Please Help!

Shubham Kushwah
  • 545
  • 1
  • 9
  • 16
  • 2
    Have you tried changing the `db_table` property of `Meta` class of your model? – Nayan Oct 19 '17 at 11:27
  • @Nayan How to change `db_table`? – Shubham Kushwah Oct 19 '17 at 15:32
  • posible duplicated https://stackoverflow.com/questions/2862979/easiest-way-to-rename-a-model-using-django-south – Mauricio Cortazar Oct 19 '17 at 16:28
  • @ShubhamKushwah see the documentation here https://docs.djangoproject.com/en/1.11/ref/models/options/#db-table You can set the table name in `db_table` option – Nayan Oct 23 '17 at 05:29
  • 1
    In my case, I had to rename the table(via `db_table` option) and not the model name. I simply changed the `db_table` value and ran `makemigations` and `migrate`. The table rename was successful. – Taranjeet May 27 '19 at 06:40

1 Answers1

2

Maybe change the model name in models.py file and run makemigrations and the migrate.

rajkris
  • 1,775
  • 1
  • 9
  • 16