Skip to content

migrate:fresh fails to drop tables due to FK constraints on mysql #913

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

Open
elgow opened this issue Dec 20, 2024 · 1 comment
Open

migrate:fresh fails to drop tables due to FK constraints on mysql #913

elgow opened this issue Dec 20, 2024 · 1 comment
Labels
bug An existing feature is not working as intended

Comments

@elgow
Copy link

elgow commented Dec 20, 2024

Describe the bug
migrate:fresh fails to drop tables because of FK constraints on mysql. This is true both with and w/o the -f option.

To Reproduce
Steps to reproduce the behavior:

  1. On a mysql DB, create a migration that defines a schema with two tables A and B where B has a FK on A with FK constraint
        with self.schema.create("A") as table:
            table.increments("rowid").primary()

        with self.schema.create("B") as table:
            table.increments("rowid").primary()
            table.unsigned_integer('a_id', nullable=False)
            table.foreign('a_id').references('rowid').on('A')

  1. Run masonite-orm migrate:fresh (will succeed)
  2. Run masonite-orm migrate:fresh (will fail, see below)
  3. See error

Expected behavior
Should delete all tables and re-create the schema

Actual results
"Cannot drop table 'A' referenced by a foreign key constraint 'b_a_id_foreign' on table 'B'.")

Desktop (please complete the following information):

  • OS: Rocky linux
  • Version: "8.6 (Green Obsidian)"

What database are you using?

  • Type: mysql
  • Version 8.0.30
  • Masonite ORM 2.23.2

Additional context
If you rename A to C so that the alpha order is reversed then it will work. It seems that the table deletion is done in alpha order rather than based on a dependency graph. The -f argument fails to disable the FK constraints so that the table drop may proceed.

@elgow elgow added the bug An existing feature is not working as intended label Dec 20, 2024
@elgow
Copy link
Author

elgow commented Dec 20, 2024

Relates to #861

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An existing feature is not working as intended
Projects
None yet
Development

No branches or pull requests

1 participant