-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Migrations fail after upgrading from 1.1.1 to 2.0 - string foreign key is not defaulted to 450 characters #9795
Comments
In the 1.1, the following code was generated for a string key:
In 1.2, the following code gets generated:
The |
I investigated this. We are generating different migrations but migration generated with 1.1.2 packages with string PK is working correctly in 2.0.0 packages. While it does not have type specified explicitly, it infers type from the model built by Designer code. Since migrations add migration & designer files both, they are consistent. But if the table being created in migration is not found in designer's model (no entityType with ToTable call to given table) then we cannot infer type and generate Removing this from milestone for re-triage. |
Notes from triage: As @smitpatel says, this seems to be functional as long as the model is up-to-date. However, assigning to @bricelam to investigate further since we should really not be specifying the type explicitly in this case since the type mapper will generate the same type by convention, which means that the Migration can be more provider-agnostic if the type is not specified explicitly. |
I believe I fixed this in #9469. I'll confirm before closing. |
Confirmed. We'll no longer generate the by-convention type in 2.0.1. |
Hi, we have a public test feed that you can use to try out the ASP.NET/EF Core 2.0.3 patch! To try out the pre-release patch, please refer to the following guide:
We are looking for feedback on this patch. We'd like to know if you have any issues with this patch by updating your apps and libraries to the latest packages and seeing if it fixes the issues you've had, or if it introduces any new issues. If you have any issues or questions, please reply on this issue to let us know as soon as possible. Thanks, |
So if I understand correctly this only works if the migration and the entity are in sync? |
No, we let the provider re-calculate the column type using the same information it used for the model at the time the migration was generated |
(This is the same as it worked in all previous versions of EF Core. We inadvertantly regressed the behavior in 2.0.0.) |
I couldn't get it working. How would it know the model used at the time the migration was generated? |
It's in the *.Designer.cs file. |
Oh, I see it. However, the sql script generated is still using nvarchar(max) for the string primary key in my case, which is causing failure... I managed to regenerate a new initial migration file with ef 2.0) to replace all the existing ones, by following this post https://weblog.west-wind.com/posts/2016/Jan/13/Resetting-Entity-Framework-Migrations-to-a-clean-Slate |
We have a large project for which we keep the entire history of all migrations.
Any developer can checkout the project and run all the migrations on their local db server to create their own db.
This worked great until we tried to upgrade from 1.1.1 to 2.0
We use asp.net on top of .net framework 4.6.1 with sql server 2016.
We have upgraded our csproj file as follows:
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
In 1.1.1, the migration used to automatically create any string primary/foreign keys with a default length of 450, which is the max size allowed for sql server.
It appears that in 2.0, the automatic length is not applied, causing all our string primary key and foreign key migration statements to fail.
We figured out that we can manually add the maxlength in the migrations, but is there a better way to handle this breaking change?
We do not want to recreate a huge single initial migration because we are not sure whether some migrations we manually modified, and the loss of flexibility to deploy on various databases that may not have all migrations ran yet.
Please in the future document all breaking changes in the migration documentation.
https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/
The text was updated successfully, but these errors were encountered: