-
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
To change the IDENTITY property of a column, the column needs to be dropped and recreated #7444
Comments
Duplicate of #329, planned for the next release of EF Core. |
Searched prior to submission but didn't find that :) Thanks will follow that issue |
No problem, it's not obvious from the title of #329 😄 |
I'll post a small question here to you @rowanmiller :) I have a model (most properties excluded) // .HasKey(entity => new { entity.InfluencerId, entity.OfferingId });
public class OfferingInfluencer
{
public int InfluencerId { get; set; }
[ForeignKey("InfuencerId")]
public Profile Influencer { get; set; }
public long OfferingId { get; set; }
[ForeignKey("OfferingId")]
public Offering Offering { get; set; }
}
public class Offering
{
[Key]
public long Id { get; set; }
//[InverseProperty("Offering")]
public virtual ICollection<OfferingInfluencer> Influencers { get; set; }
} The table for Offering is
If I add the InverseProperty-attribute to Migration.csprotected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_OfferingInfluencer_Profiles_InfuencerId",
table: "OfferingInfluencer");
migrationBuilder.DropIndex(
name: "IX_OfferingInfluencer_InfuencerId",
table: "OfferingInfluencer");
migrationBuilder.DropColumn(
name: "InfuencerId",
table: "OfferingInfluencer");
migrationBuilder.AddForeignKey(
name: "FK_OfferingInfluencer_Profiles_InfluencerId",
table: "OfferingInfluencer",
column: "InfluencerId",
principalTable: "Profiles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
} SQL
Is this a bug or just me that doesn't grasp how to model relationships correctly? :) Glad if you can enlighten me or point me to some good resource when to use |
@joacar you shouldn't really need to use any of the attributes in this model, since there is a single pair of navigations between each class, and the foreign keys should be picked up by convention. That said, what you described sounds like a bug, so please open a new issue and include the full code listing to reproduce the behavior. |
Just adding it here so I won't forget it when I have (take..) time to create a repro solution. The domain model // Dependent
public class PublishedOffering
{
[Key]
public long OfferingId { get; set; }
public virtual Offering Offering {get ;set }
}
// Principal
public class Offering
{
public long Id { get; set; }
public virtual PublishedOffering Published { get; set; }
} Creating a migration produces the FK-constraint correctly but the index name Adding |
I get this problem whilst following this tutorial, with the latest version of EF Core. https://www.codeproject.com/Articles/1210559/Asp-net-core-Angular-Build-from-scratch-a-web-appl All the tutorial is attempting to do is add one table to a blank existing SQL Server database (on localhost), and I get this error about "To change the IDENTITY property of a column, the column needs to be dropped and recreated." Which damn table is it referring to ?! Why don't the error messages quote the SQL it's fallen over on ? Yesterday, I couldn't even get most of that tutorial to build, until i upgraded VS2017 to the latest version. VS Core didn't even recognise that I'd added AutoMapper to my project. Today, following the upgrade, the code does build okay (but this IDENTITY error continues). Last week, I was trying to follow an ASP.Net Core tutorial on Microsoft's own website. It was 5 months old, and already out of date, and hopeless. I was Googling for unexpected error messages within 13 minutes of starting the tutorial. This whole ASP.Net Core and EF Core stuff... it's just not stable. Even now, in November 2017, it's just not ready yet. Far from it. I've never wasted so many man-hours Googling for error message after error message. |
MikeInSwitzerland, I am trying to run it too. did you were able to solve the issue? |
I am trying to follow https://www.codeproject.com/Articles/1210559/Asp-net-core-Angular-Build-from-scratch-a-web |
we have hit this today for a change in Identity user Id datatype.. not so easy change I guess. I expect at least ef migration handle script change and leave data change to user. |
@joacar Thanks for posting, I'm dealing with the same issue |
I have managed it by hiding the change (All existing migrations are updated manually). Injected an additional script to handle the database changes. |
@rowanmiller I am using EF Core 2.1 (Latest Stable Version). But still facing similar issue. Can you please check & suggest Thanks |
Still the same issue... |
Changing an identity pk to composite key
Steps to reproduce
Can't recall if doing schema compare in VS created the temporary table and did the data moving or not. For now I just deleted the previous data so no data migration needed to take place, but perhaps EF generates the same as Schema Compare does (or don't :)
Further technical details
EF Core version: 1.1.0
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
IDE: Visual Studio Community 2017 RC
The text was updated successfully, but these errors were encountered: