tworzę ten model jako część mojego kodu pierwszego Entity FrameworkEntity Framework 5 Wiele kolumn tożsamości określonych dla tabeli. Tylko jest dozwolona jedna kolumna tożsamości za stołem
public class NewUserRegistration
{
[Key]
public int NewUserRegistrationId { get; set; }
}
pomocą polecenia Update-Database -Verbose -Force
w Pakiecie Manger ConsoleI uzyskać ten wyjątek podczas tego kawałka aktualizacji Applying automatic migration: 201211252223088_AutomaticMigration.
.
ALTER TABLE [dbo] [NewUserRegistration] Dodano [NewUserRegistrationId] [int] NOT NULL IDENTITY System.Data.SqlClient.SqlException (0x80131904): Wiele kolumny tożsamości określone dla tabeli "NewUserRegistration". Dozwolona jest tylko jedna kolumna tożsamości na tabelę. w System.Data.SqlClient.SqlConnection.OnError (wyjątkiem SQLException, logicznego breakConnection, działania
1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 wrapCloseInAction) w System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning (TdsParserStateObject stateObj, logiczna callerHasConnectionLock, logiczna asyncClose) w System. Data.SqlClient.TdsParser.TryRun (runBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader datastream BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, logiczna & DATAREADY) w System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds (ciąg methodName, logiczna asynchronicznymi Int32 timeout) pod adresem S. ystem.Data.SqlClient.SqlCommand.InternalExecuteNonQuery (TaskCompletionSource migrationStatements) w System.Data.Entity.Migrations.Infrastructure.MigratorBase.ExecuteStatements (IEnumerable1 migrationStatements) at System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, XDocument targetModel, IEnumerable
1 operacje Boolean Obniżanie, Boolean auto) w System.Data. Entity.Migrations.DbMigrator.AutoMigrate (String migrationId, XDocument sourceModel, XDocument targetModel, Boolean obniżenia) na System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.AutoMigrate (String migrationId, XDocument sourceModel, XDocument targetModel, Boolean downgrading) pod adresem System.Data.Entity.Migrations.DbMigrator.Upgrade (IEnumerable pendingMigrations, łańcuch targetMigrationId, String lastMigrationId)
w System.Data.Entity.Migrations.DbMigrator.Update (ciąg targetMigration) w System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update (ciąg targetMigration) w System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.RunCore ()() przy System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run ClientConnectionId: a39395da-5f2b-48e0-bdac-b48d75a68c68 Wiele kolumn tożsamości określonych dla tabeli "NewUserRegistration". Dozwolona jest tylko jedna kolumna identyfikacyjna na tabelę.
Wyraźnie podano tylko jedną kolumnę tożsamości. Dlaczego tak się dzieje?
Kiedy to robię, nie mam wyjątków.
public class NewUserRegistration
{
[Key]
public int Id { get; set; }
}
Wszelkie uwagi na temat tego, dlaczego tak się dzieje?
EDIT
muszę powiedzieć, że jestem zmieniając nazwę klucza. Komentarze mówią, że nie możesz tego po prostu zrobić. Jak mogę upuścić i odtworzyć?
Czy najlepiej usunąć bazę danych z SQL, a następnie ponownie uruchomić komendę Update-Database
?
wygląda zmieniasz istniejącą tabelę. Czy przed dodaniem 'NewUserRegistrationId' masz inny klucz w obiekcie? Kolumn tożsamości nie można po prostu zmienić. –
tak, więc jak mam polecić, aby upuścić i odtworzyć stół. – Peter