-
Notifications
You must be signed in to change notification settings - Fork 380
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
.Net Core2 EF MySQL having issue while changing foreign key column to nullable #483
Comments
Can you generate the SQL? It appears that it's a SQL syntax error so that should provide some clues. |
It is not generating any SQL, I have already tried it. It gives same error
when I run 'dotnet ef migrations script' command
…On Thu, Feb 8, 2018, 23:16 mguinness ***@***.***> wrote:
Can you generate the SQL
<https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/#generating-a-sql-script>?
It appears that it's a SQL syntax error so that should provide some clues.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#483 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AIcy3L4ZQKlICMAtRFQJk8RuFTFBNWbfks5tSzLygaJpZM4R98p8>
.
|
Turn "Microsoft" logging to "Information" then run your migrations and it will log SQL. Example (change Microsoft: error to Microsoft: information) |
@caleblloyd, Thanks man I got this fix. Actually I was using MySQL official connector for this which was causing the issue. Later I tried same scenario with Pomelo.EntityFrameworkCore.MySql and it worked exactly same as expected. !!! Pomelo Rocks !!! |
I am working on an application where I am using .Net Core 2, EF Core and MySQL as database server via Code First approach.
I have 2 tables:
User table is the main table which contains the user information and Employee table is the child table which has a column ID_User as shown below:
Everythihg works perfectly when I use the above mapping and I have enaugh data in both the tables.
Now, I want to make the column ID_User in Employee table as nullable
To implement this change I made folloeing change to my model:
and in mapping file:
builder.HasOne(x=>x.User).WithMany(y=>y.Employees).HasForeignKey(z=>z.ID_User).IsRequired(false);
After running the dotnet ef migrations add empuser command it generated the following migration code:
migrationBuilder.DropForeignKey(
name: "FK_Employee_User_ID_User",
table: "Employee");
Now when I run dotnet ef database update it is giving me the following error:
Please help.
Thanks
The text was updated successfully, but these errors were encountered: