NuGet/NuGetGallery — Issue #263: Database error when running the website from a clean state
Author: dotnetjunky
Created: 2011-11-22 21:20:08+00:00
State: open

I just pulled the latest code from github and now when I run the website from a clean state with no database pre-created, I get the error below. Can someone look at this ASAP?

Server Error in '/' Application.
________________________________________
Introducing FOREIGN KEY constraint 'PackageOwnerRequest_RequestingOwner' on table 'PackageOwnerRequests' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Could not create constraint. See previous errors.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Introducing FOREIGN KEY constraint 'PackageOwnerRequest_RequestingOwner' on table 'PackageOwnerRequests' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Could not create constraint. See previous errors.

Source Error:

Line 26: {
Line 27: var settingsRepo = new EntityRepository(entitiesContext);
Line 28: settings = settingsRepo.GetAll().FirstOrDefault();
Line 29: }
Line 30:

Source File: E:\aspnet\nugetgallery\Website\App_Start\ContainerBindings.cs Line: 28

Stack Trace:

[SqlException (0x80131904): Introducing FOREIGN KEY constraint 'PackageOwnerRequest_RequestingOwner' on table 'PackageOwnerRequests' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Could not create constraint. See previous errors.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +2084770
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5084476
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2275
System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async) +228
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +326
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +137
System.Data.SqlClient.<>c__DisplayClassa.b__8(SqlConnection conn) +38
System.Data.SqlClient.SqlProviderServices.UsingConnection(SqlConnection sqlConnection, Action`1 act) +98
System.Data.SqlClient.SqlProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection) +361

[InvalidOperationException: The database creation succeeded, but the creation of the database objects did not. See InnerException for details.]
System.Data.SqlClient.SqlProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection) +411
MvcMiniProfiler.Data.ProfiledDbProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection) in C:\Users\sam\Desktop\mvc-mini-profiler\MvcMiniProfiler\Data\ProfiledDbProviderServices.cs:51
System.Data.Objects.ObjectContext.CreateDatabase() +84
System.Data.Entity.Internal.DatabaseOperations.Create(ObjectContext objectContext) +8
System.Data.Entity.Database.Create() +76
System.Data.Entity.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext context) +387
System.Data.Entity.Internal.<>c__DisplayClass5.b__3() +19
System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) +72
System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() +169
System.Data.Entity.Internal.LazyInternalContext.b__4(InternalContext c) +7
System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input) +118
System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action) +190
System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase() +73
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +28
System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +62
System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() +15
System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider() +37
System.Linq.Queryable.FirstOrDefault(IQueryable`1 source) +50
NuGetGallery.ContainerBindings.Load() in E:\aspnet\nugetgallery\Website\App_Start\ContainerBindings.cs:28
Ninject.Modules.NinjectModule.OnLoad(IKernel kernel) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Modules\NinjectModule.cs:60
Ninject.KernelBase.Load(IEnumerable`1 modules) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\KernelBase.cs:222
Ninject.KernelBase..ctor(IComponentContainer components, INinjectSettings settings, INinjectModule[] modules) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\KernelBase.cs:102
Ninject.KernelBase..ctor(INinjectModule[] modules) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\KernelBase.cs:57
Ninject.StandardKernel..ctor(INinjectModule[] modules) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\StandardKernel.cs:31
NuGetGallery.Container.<.cctor>b__0() in E:\aspnet\nugetgallery\Website\App_Start\Container.cs:8
System.Lazy`1.CreateValue() +361
System.Lazy`1.LazyInitValue() +104
System.Lazy`1.get_Value() +89
NuGetGallery.Container.get_Kernel() in E:\aspnet\nugetgallery\Website\App_Start\Container.cs:14
NuGetGallery.App_Start.NinjectMVC3.CreateKernel() in E:\aspnet\nugetgallery\Website\App_Start\NinjectMVC3.cs:38
Ninject.Web.Mvc.Bootstrapper.Initialize(Func`1 createKernelCallback) in c:\Projects\Ninject\Maintenance2.2\ninject.web.mvc\mvc3\src\Ninject.Web.Mvc\Bootstrapper.cs:61
NuGetGallery.App_Start.NinjectMVC3.Start() in E:\aspnet\nugetgallery\Website\App_Start\NinjectMVC3.cs:21

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner) +0
System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner) +72
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +335
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +28
System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +19
WebActivator.BaseActivationMethodAttribute.InvokeMethod() +221
WebActivator.ActivationManager.RunActivationMethods() +342
WebActivator.ActivationManager.RunPreStartMethods() +28
WebActivator.ActivationManager.Run() +55

[InvalidOperationException: The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message: Exception has been thrown by the target of an invocation..]
System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +423
System.Web.Compilation.BuildManager.CallPreStartInitMethods() +306
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +677

[HttpException (0x80004005): The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message: Exception has been thrown by the target of an invocation..]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9080076
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256

________________________________________
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.468