4

I've just started working with Django, and when setting up my models and db I picked a name which I would like to change now. Is it OK to just edit models.py (rename the class), then run makemigrations and migrate on it? I have a table set up in the db (SQLite), but no entries yet.

I'm new to database migration too. Does this cover what I want to do?

Thanks.

Community
  • 1
  • 1
ChrisM
  • 2,128
  • 1
  • 23
  • 41
  • Is that model referred by other models? Did you have a migration already generated from the original schema? – Shang Wang Aug 17 '15 at 19:12
  • No, there's a single model, so no references to it from anything else. I have called `makemigrations` and `migrate`, and have a 0001_initial.py file under /migrations. – ChrisM Aug 17 '15 at 19:20

1 Answers1

6

After renaming of model in the models.py, run makemigrations. The question should appear "Did you rename the xxx model to yyy? [y/N]" Press y and it will be enough in your case.

UPD: In general, you should run makemigrations and migrate every time when you change code in models.py. You should manually edit migrations files (created by makemigrations) only in few cases, when the Django isn't smart enough to understand what you want to do.

svfat
  • 3,273
  • 1
  • 15
  • 34
  • Then `migrate` to apply that change? That's what's suggested when I run the server. Excuse my ignorance, new to the whole concept of migrations! It seems rather akin to version control. – ChrisM Aug 17 '15 at 19:40