Note that there are some explanatory texts on larger screens.

plurals
  1. POSeeding and Branching projects using entity framework migrations
    primarykey
    data
    text
    <p>I'm working on a project using entity framework code first 4.3 using migrations. When running locally my web.config is configured to target a database initialzer which implements <code>CreateDatabaseIfNotExists&lt;DataContext&gt;</code> which seeds my development database with test data but also populating various 'static' lookuptable data first time it's run.</p> <p>Once the development database has been created any subsequent changes to the database is done adding migrations to the project and updating the database with the 'updata-database' PS command. </p> <p>When I'm happy with project I deploy the code with webdeploy but copy the database manually since webdeploy doesn't include the migrations table. When deploying I use a web.config transform to set a new database initializer that implements <code>MigrateDatabaseToLatestVersion&lt;DataContext&gt;</code>. This would then apply new code based migrations deployed afterwards. This is all working reasonably well but I have concerns whether this is the best approach to initialize my db not only with test data but also data that required to run the application. What I'm looking for is a good way to create that initial seed data without having to hook it into the <code>CreateDatabaseIfNotExists&lt;DataContext&gt;</code> but instead hooking it into Migrations. I realise there is a seed method on the configuration class but seeing as it's updating the database with every migration this is not desirable solution.</p> <p>The project is in TFS and from time to time I need to create a new branch of this project which is essence is a clone of the first. When running this locally for the first time the database doesn't exist yet but will be created and seeded as explained earlier. Biggest problem now is that schema changes previously handled through migrations will now be applied when the database is created for the first time. If I then try to add a new migration file and run 'update-database' I run into a wall since it can't run previous migrations because those changes was already applied when the database was created. I can only Imagine I'm doing something wrong here or simply missed a trick.</p> <p>In conclusion I'm looking for information regarding</p> <ol> <li>Best way to seed initial test data &amp; required application data when creating the database for the first time using migrations.</li> <li>Best way to overcome problems when branching a project containing code migrations and having to create the database for the first time.</li> </ol> <p>Thanks for reading.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload