question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Changing options for STATUS is not triggering new db migrations like desired

See original GitHub issue

Given that behind the scenes we are having syntax sugar for a CharField with some fixed choices, I was expecting the same behavior, which is: any change on the choices tuple causes a new migration.

Having a model like this:

class Article(StatusModel):
    STATUS = Choices('draft', 'published')

if I later modify it like this,

class Article(StatusModel):
    STATUS = Choices('draft', 'published', 'finished')

manage.py makemigrations reports No changes detected

However, if the new option added is the first one, like here

class Article(StatusModel):
    STATUS = Choices('predraft', 'draft', 'published')

manage.py makemigrations creates a new migration

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

1reaction
romgarcommented, Nov 21, 2016

Hi @jmansilla !

I guess the answer is related to this part of the documentation: [...] sets its default value to the first item in the STATUS choices.

That explains the different behaviors you encountered. In the first situation, you add a value at the end, which doesn’t impact the default value of the StatusField.

But when you add a new value at the beginning, this changes the default value from your StatusField, which Django detects to trigger a new migration.

If you don’t want this behavior, fixing a default value for your StatusField would solve your issue, as you will then be insensitive to your choice list ordering.

I’m not a great fan of hidden logic like “the first one is the default value” without being really explicit, but the documentation explains it, and changing now this behavior would probably annoy a lot of people that didn’t set any default value for their StatusField.

@nemesisdesign we would need a bit more context to help you, like your models, your migrations, …

0reactions
ivanschecommented, Jul 1, 2019

+1 I have a bunch of migrations which enumerate the possible statuses, but adding a new status does not seem to affect existing migrations

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rails: I update migration file then run db ... - Stack Overflow
I've added the field in the migration file (under db\migrate), then ran 'rake db:migrate' which ran without troubles. My text editor even told...
Read more >
Managing Migrations - EF Core - Microsoft Learn
You are free to move Migrations files and change their namespace manually. New migrations are created as siblings of the last migration.
Read more >
Versioned Migrations | ent - Entgo.io
We emphasize to use the first option, as it has the advantage of not having to connect to a production database to create...
Read more >
How to Migrate a Database in PHP Using Phinx
What Are Database Migrations? ... In basic terms, migrations contain changes that you wish to make to your database. These changes could be ......
Read more >
Django Migrations: A Primer - Real Python
SQL is also used to create, change, and delete the database tables themselves. Working directly with SQL can be quite cumbersome, so to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found