Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9250779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:31:46+00:00 2026-06-18T10:31:46+00:00

I had to stop at the same stages following different MVC 4 code first

  • 0

I had to stop at the same stages following different MVC 4 code first technique tutorials, because database initialization failed.

Using the connection

<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-DbTestApp-20130205173443;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-DbTestApp-20130205173443.mdf" providerName="System.Data.SqlClient" />

I can’t even create or manage the database, which I want to be generated from my models

public class Category
    {
        public int Id { get; set; }

        [Required]
        [MinLength(4)]
        [MaxLength(64)]
        public string Name { get; set; }

        public virtual IEnumerable<Article> Articles { get; set; }
    }

    public class Article
    {
        public int Id { get; set; }

        public int CategoryId { get; set; }
        public virtual Category Category { get; set; }

        [Required]
        [MinLength(4)]
        [MaxLength(64)]
        public string Title { get; set; }

        [Required]
        [MinLength(16)]
        [MaxLength(1024)]
        [DataType(DataType.MultilineText)]
        public string Content { get; set; }

        [Required]
        [Display(Name = "Post Anonymous?")]
        public bool IsAnonymous { get; set; }

        public int AuthorId { get; set; }
        public virtual Author Author { get; set; }

        public virtual IEnumerable<Comment> Comments { get; set; }

    }

    public class Author
    {
        public int Id { get; set; }

        [MinLength(3)]
        [MaxLength(64)]
        public string AuthorName { get; set; }

        public virtual IEnumerable<Article> Articles { get; set; }

        public virtual IEnumerable<Category> Categories { get; set; }
    }

    public class Comment
    {
        public int Id { get; set; }

        public int ArticleId { get; set; }
        public virtual Article Article { get; set; }

        [Required]
        [MinLength(3)]
        [MaxLength(64)]
        public string Author { get; set; }

        [MaxLength(64)]
        public string Title { get; set; }

        [Required]
        [MinLength(4)]
        [MaxLength(512)]
        public string Content { get; set; }
    }

using the context below

    public class BlogContext : DbContext
    {
        public DbSet<Category> Categories { get; set; }
        public DbSet<Article> Articles { get; set; }
        public DbSet<Author> Authors { get; set; }
        public DbSet<Comment> Comments { get; set; }

        public BlogContext()
            : base("DefaultConnection")
        {
            Configuration.ProxyCreationEnabled = false;
        }
    }

I also set the initializer in Global.asax Application_Start() method:

Database.SetInitializer(new DropCreateDatabaseIfModelChanges<BlogContext>());

The problem comes when I’m trying to call

var articles = db.Articles.Include(a => a.Category).Include(a => a.Author);

inside my BlogController’s Index() method to return a view with the list of stored articles. That happens every time calling a DB related methods, the error message is:

Model compatibility cannot be checked because the database does not contain model metadata. Model compatibility can only be checked for databases created using Code First or Code First Migrations.

In the tutorials I found nothing about problems like that and the solutions I read couldn’t solve the problem.

Any ideas?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:31:48+00:00Added an answer on June 18, 2026 at 10:31 am

    DropCreateDatabaseIfModelChanges requires there to be a previous model already in place before it will compare the two. To start up the database you’ll need to use the DropCreateDatabaseAlways initializer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had used the following SQL to list out all jobs without a stop
I setup Hadoop, formatted the HDFS, ran bin/start-all.sh, ran bin/stop-all.sh and had no problems.
Had this working; at one stage. The problem is the following text is now
I had a question in MySQL, did it correctly. But the book code differs
I'm seriously about to stop coding and become a carpenter. This problem has had
How can I stop a particular user from accessing the database for a period
I just had my server upgraded from Centos 4.9 to Centos 6.2 The following
In frame 1 of a very simple flash file, I have the following code:
I had a question earlier involving php and mysql on this same project, This
I thought I finally had managed to write my first init.d script properly but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.