के लिए स्वचालित माइग्रेशन इसलिए मैंने अपने नए एमवीसी 4 प्रोजेक्ट के साथ स्वचालित माइग्रेशन का उपयोग करने की कोशिश की लेकिन किसी भी तरह यह काम नहीं कर रहा है। मैं followed this blog post कदम से कदम।एएसपी.NET SimpleMembershipProvider
[Table("UserProfile")]
public class UserProfile
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string UserName { get; set; }
public int NotaryCode { get; set; }
}
तो मैं पैकेज प्रबंधक कंसोल enable-migrations
पर लिखा था और एक विन्यास वर्ग (DbMigrationsConfiguration<Web.Models.UsersContext>
से विरासत में मिली) दिखाई दिया तो मैं भरने:
मैं UserProfile
खाता मॉडल में परिवर्तन (NotaryCode
क्षेत्र) जोड़ दिया है वर्ग के रूप में:
public Configuration()
{
AutomaticMigrationsEnabled = true;
}
protected override void Seed(Atomic.Vesper.Cloud.Web.Models.UsersContext context)
{
WebSecurity.InitializeDatabaseConnection(
"DefaultConnection",
"UserProfile",
"UserId",
"UserName", autoCreateTables: true);
if (!Roles.RoleExists("Atomic"))
Roles.CreateRole("Atomic");
if (!Roles.RoleExists("Protocolista"))
Roles.CreateRole("Protocolista");
if (!Roles.RoleExists("Cliente"))
Roles.CreateRole("Cliente");
string adminUser = "randolf";
if (!WebSecurity.UserExists(adminUser))
WebSecurity.CreateUserAndAccount(
adminUser,
"12345",
new { NotaryCode = -1 });
if (!Roles.GetRolesForUser(adminUser).Contains("Atomic"))
Roles.AddUsersToRoles(new[] { adminUser }, new[] { "Atomic" });
}
और फिर मैं update-database -verbose
भागने की कोशिश की, लेकिन यह काम नहीं करता। मेरा मतलब है, यह आउटपुट है:
डेटाबेस में 'UserProfile' नामक एक ऑब्जेक्ट पहले से ही है।
PM> update-database -verbose
Using StartUp project 'Web'.
Using NuGet project 'Web'.
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Target database is: 'VesperCloud' (DataSource: .\SQLSERVER, Provider: System.Data.SqlClient, Origin: Configuration).
No pending code-based migrations.
Applying automatic migration: 201211051825098_AutomaticMigration.
CREATE TABLE [dbo].[UserProfile] (
[UserId] [int] NOT NULL IDENTITY,
[UserName] [nvarchar](max),
[NotaryCode] [int] NOT NULL,
CONSTRAINT [PK_dbo.UserProfile] PRIMARY KEY ([UserId])
)
System.Data.SqlClient.SqlException (0x80131904): There is already an object named 'UserProfile' in the database.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at System.Data.Entity.Migrations.DbMigrator.ExecuteSql(DbTransaction transaction, MigrationStatement migrationStatement)
at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ExecuteSql(DbTransaction transaction, MigrationStatement migrationStatement)
at System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable`1 migrationStatements)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.ExecuteStatements(IEnumerable`1 migrationStatements)
at System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, XDocument targetModel, IEnumerable`1 operations, Boolean downgrading, Boolean auto)
at System.Data.Entity.Migrations.DbMigrator.AutoMigrate(String migrationId, XDocument sourceModel, XDocument targetModel, Boolean downgrading)
at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.AutoMigrate(String migrationId, XDocument sourceModel, XDocument targetModel, Boolean downgrading)
at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.RunCore()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
ClientConnectionId:a7da0ddb-bccf-490f-bc1e-ecd2eb4eab04
**There is already an object named 'UserProfile' in the database.**
मुझे पता है कि वस्तु मौजूद है। मेरा मतलब है, मैं डीबी के मैन्युअल रूप से पुनर्निर्माण किए बिना स्वचालित-माइग्रेशन का उपयोग, सटीक, संशोधित और चलाने के लिए प्रयास कर रहा हूं। लेकिन किसी भी तरह यह काम नहीं कर रहा है।
मैं MSDN प्रलेखीकरण देखने के लिए और संपत्ति मिली:
AutomaticMigrationDataLossAllowed = true;
लेकिन यह सच के लिए सेटिंग कुछ भी नहीं बदलता है। मुझे लगता है कि मुझे कुछ याद आ रहा है लेकिन किसी भी तरह से यह नहीं मिला है। कोई उपाय?
कृपया http://stackoverflow.com/questions/26305273/there-is-already-an-object-named-in-the-database/28316226#28316226 पर मेरा उत्तर को देखने आशा इस मदद करता है ... –