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

Bug report: Not work migrate on foreign_keys=1 #218

Open
alteralt opened this issue Jan 4, 2023 · 1 comment
Open

Bug report: Not work migrate on foreign_keys=1 #218

alteralt opened this issue Jan 4, 2023 · 1 comment

Comments

@alteralt
Copy link
Contributor

alteralt commented Jan 4, 2023

Describe the bug
Error in migration execution

To Reproduce
Steps to reproduce the behavior:

  1. Write and run code:
import peewee
import peewee_migrate


db = peewee.SqliteDatabase(":memory:", pragmas={"foreign_keys": 1})


class User(peewee.Model):
    class Meta:
        database = db


class TgAccount(peewee.Model):
    owner = peewee.ForeignKeyField(User)

    class Meta:
        database = db


for model in [User, TgAccount]:
    model.create_table()


user = User.create()

TgAccount.create(owner=user)


migrator = peewee_migrate.Migrator(db)
migrator.add_fields(
    User, name=peewee.CharField(default="John")
)
migrator.run()

Expected behavior
Migration will be executed

Screenshots
image

Desktop (please complete the following information):

  • peewee-migrate 1.6.5
  • peewee 3.15.4
  • python 3.11

Additional context
I understand this is happening because of foreign_keys=1.
If this value is removed, the migration will be completed successfully

Perhaps it should be done so that the library automatically changes foreign_keys to 0 when using SQLiteDatabase?

@alteralt
Copy link
Contributor Author

alteralt commented Jan 4, 2023

I fixed it in my code like this. Probably not the best solution

image

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

1 participant