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

Fluent's deleteForeignKey doesn't generate a valid SQL command #297

Closed
anthonycastelli opened this issue Jul 21, 2017 · 4 comments
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@anthonycastelli
Copy link
Member

anthonycastelli commented Jul 21, 2017

After spending a bit of time trying to figure out why Fluent's deleteForeignKey(...) wouldn't delete foreign keys, I discovered that the actual SQL command isn't valid.

When using the database's modify command like so

try database.modify(Child.self) { builder in
    builder.deleteForeignKey("user_id, referencing: "id", on: User.self)
}

the SQL query generated returns

ALTER TABLE 'children' DROP 'user_id', DROP '_fluent_fk_children.user_id-users.id'

This isn't valid for deleting key constraints. The correct query should read

ALTER TABLE 'children' DROP 'user_id', DROP FOREIGN KEY '_fluent_fk_children.user_id-users.id'
@anthonycastelli anthonycastelli changed the title Fluent's deleteForeignKey dent generate a valid SQL command Fluent's deleteForeignKey doesn't generate a valid SQL command Jul 23, 2017
@tanner0101 tanner0101 added the bug Something isn't working label Aug 7, 2017
@tanner0101 tanner0101 added this to the 2.1.3 milestone Aug 7, 2017
@tanner0101 tanner0101 self-assigned this Aug 7, 2017
@tanner0101
Copy link
Member

@anthonycastelli which driver are you using? This is likely specific to that SQL flavor and should be fixed there.

@anthonycastelli
Copy link
Member Author

@tanner0101 I'm using MySQL. Should I move this to the MySQL Driver?

@tanner0101
Copy link
Member

That would be helpful! Probably needs to be fixed in a similar manner to this: https://github.com/vapor/mysql-driver/blob/master/Sources/MySQLDriver/MySQLSerializer.swift#L47-L65

@tanner0101
Copy link
Member

Marking this to ensure there is a test case going forward.

@tanner0101 tanner0101 added this to Todo in Vapor 3 Feb 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants