Skip to content

Cannot add foreign key constraint mysql/mysql #318

Open
@huxiangquan

Description

@huxiangquan

2025-02-12T14:02:05.203686664+08:00 INFO default_logger - ddl begin: ALTER TABLE abplearn.sale_return_line_item ADD CONSTRAINT fk_srli_tran_id FOREIGN KEY (tran_id) REFERENCES abplearn.sale_transaction(tran_id)

2025-02-12T14:02:05.207894311+08:00 ERROR default_logger - ddl failed, error: sqlx error: error returned from database: 1215 (HY000): Cannot add foreign key constraint

2025-02-12T14:02:05.217009030+08:00 ERROR default_logger - panic: panicked at /project/dt-task/src/task_runner.rs:326:36:
called Result::unwrap() on an Err value: sqlx error: error returned from database: 1215 (HY000): Cannot add foreign key constraint

When attempting to create a foreign key on the sale_return_line_item table, an error occurred because the sale_transaction table had not yet been created. Could the tables be created in the order of their foreign key dependencies to avoid this issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions