Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverse db-level default #37

Open
rpradal opened this issue Dec 5, 2021 · 1 comment
Open

Reverse db-level default #37

rpradal opened this issue Dec 5, 2021 · 1 comment

Comments

@rpradal
Copy link

rpradal commented Dec 5, 2021

Hi,

I am trying to add a new non nullable field on a model in a backward compatible way.
I understood clearly what this library achieves, but i am wondering how i can clear the default at the end.

For my first migration i have the following operations :

    operations = [
        migrations.AddField(
            model_name="transaction",
            name="currency",
            field=models.CharField(default="EUR", max_length=3),
        ),
        AddDefaultValue(model_name="transaction", name="currency", value="EUR"),
    ]

And for the second one :

    operations = [
        migrations.AlterField(
            model_name="transaction",
            name="currency",
            field=models.CharField(max_length=3),
        ),
    ]

This second migration does not generate any sql code so i end up with a remaining default at db level.

If there a way to remove the db level default introduced by AddDefaultValue ?

Thanks

@Isokaeder
Copy link

Interesting @rpradal . At first glance I would do something like this:

class RemoveDefaultValue(AddDefaultValue):
  def database_forwards(*args, **kwargs):
     super().database_backwards(*args, **kwargs)
     
  def database_backwards(*args, **kwargs):
     super().database_forwards(*args, **kwargs)

Can you see if that approach works for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants