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

Primary Key constraint is missing from all new migrations #71

Closed
GunnerGuyven opened this issue Mar 31, 2021 · 3 comments · Fixed by #72
Closed

Primary Key constraint is missing from all new migrations #71

GunnerGuyven opened this issue Mar 31, 2021 · 3 comments · Fixed by #72

Comments

@GunnerGuyven
Copy link

Describe the bug
The constraints argument is missing in most if not all instances of generated migrationBuilder.CreateTable calls. Especially table.PrimaryKey types.

I believe #68 may be related to this. That deals with conventional detection of PK, but it seems to be all PK constraints are actually missing in the 5.0.3-alpha2 release, even those that are manually demarked with the [<Key>] annotation.

To Reproduce
Steps to reproduce the behavior:

  1. Create new table which includes a Primary Key annotated with [<Key>] in type definition
  2. Create new migration
  3. Observe the lack of a constraints argument in CreateTable call
  4. Perform database migration
  5. If successful, observe that no Primary Key is defined for database, and if Key was int type observe failure due to the inclusion of AUTO INCREMENT that is illegal in many databases engines outside of PK.

Expected behavior
Inclusion of a clause similar to that seen in older 3.1.12 release

//EntityFrameworkCore.FSharp version 3.1.12
override this.Up(migrationBuilder:MigrationBuilder) =
        migrationBuilder.CreateTable(
            name = "OrderNumbers"
            ,columns = (fun table -> 
            {
                ID = table.Column<int>(nullable = false)
                    .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn)
                OrderNumber = table.Column<string>(nullable = true, maxLength = Nullable(10))
                TSO = table.Column<bool>(nullable = false)
                Treated = table.Column<bool>(nullable = false)
                Items = table.Column<int>(nullable = false)
                PiecesReceived = table.Column<int>(nullable = false)
                PiecesTreated = table.Column<int>(nullable = false)
                PiecesUnReleased = table.Column<int>(nullable = false)
                Memo = table.Column<string>(nullable = true)
            })
            ,constraints =
                (fun table -> 
                    table.PrimaryKey("PK_OrderNumbers", (fun x -> (x.ID) :> obj)) |> ignore
                ) 
            ) |> ignore
@simon-reynolds
Copy link
Collaborator

@GunnerGuyven
Copy link
Author

I can confirm. This appears to be addressed. I have a few edge cases yet to test, but seems good 👍

@GunnerGuyven
Copy link
Author

All cases I have encountered are covered by this fix. Thank you!

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

Successfully merging a pull request may close this issue.

2 participants