I was following this to create a simple MVC application. After creating the model, when I tried to add controller, I got the following error :
I just solved this problem. Even though I am new to MVC, I am bit embarrassed to say, I was trying a work around for another problem I was having and moved my SetInitializer into my classname : DbContext class.
The app worked just fine and the database was created fine as I changed the models but I couldn't add new controllers or modify current controllers using the scaffolding tool.
I began receiving errors. One of them is listed above and another is:
Unable to retrieve meta data for 'namespace.Models.class'. A file
activation error occurred. The physical file name '\name.mdf'
may be incorrect. Diagnose and correct additional errors, and retry the
operation.
CREATE DATABASE failed. Some file names listed could not be created.
Check related errors.
Moving the SetInitializer back into my Global.asax fixed the problem.
I found the solution. the problem is the "|DataDirectory|". I Changed "|" to "\"
The error message is saying invalid value for AttachDbFilename
which is part of your MovieDbContext
connection string.
The connection string currently shows this AttachDbFilename=|DataDirectory|\Movies.mdf
so it appears the mdf file is now missing from the App_Data
folder.