none
MVC 3 - Error Execution Time - InnerException RRS feed

  • Question

  • Hello, this is the error: when I execute my application(I'm using MVC 3 and EF) it gives this error: 


    The database creation succeeded, but the creation of the database objects did not. See InnerException for details.


    and on the browser gives this: 


    Introducing FOREIGN KEY constraint 'VotoDoUsuario_Usuario' on table 'VotoDoUsuarios' 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.
    • Moved by Paul Zhou Tuesday, February 14, 2012 1:52 AM move for better support (From:Common Language Runtime)
    Sunday, February 12, 2012 11:58 PM

Answers

  • Hi ThiagoFlirt,

    I guess you're doing Entity Framework to create your database(Code First), right? If yes, you should switch cascade delete off in fulent api:

    modelBuilder.Entity<Category>() 
        .HasMany(c => c.Products) 
        .WithRequired(p => p.PrimaryCategory) 
        .HasForeignKey(p => p.PrimaryCategoryCode) 
        .WillCascadeOnDelete(false);
    Have a nice day.

    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, February 14, 2012 2:08 AM
    Moderator

All replies

  • Hi,

    Your question is regarding MVC. i suggest you to post your Question in Proper Forum.

    http://forums.asp.net/1146.aspx/1?MVC

    Regards

    Nil.

    Monday, February 13, 2012 1:34 PM
  • Hi ThiagoFlirt,

    I guess you're doing Entity Framework to create your database(Code First), right? If yes, you should switch cascade delete off in fulent api:

    modelBuilder.Entity<Category>() 
        .HasMany(c => c.Products) 
        .WithRequired(p => p.PrimaryCategory) 
        .HasForeignKey(p => p.PrimaryCategoryCode) 
        .WillCascadeOnDelete(false);
    Have a nice day.

    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, February 14, 2012 2:08 AM
    Moderator