This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hello, How do I seed the database with data as part of a migration? Thanks, Werner
|
|
|
Modify the starter code to either: * Instantiate a LightSpeed unit of work, add items to the unit of work and save changes; or * Call ExecuteNativeCommand to perform INSERT statements. |
|
|
I was hoping it would be baked into the migrations. I ran into another issue with migrations that mights be related to this. To reproduce, create an empty database, and created a migrations project using Visual Studio 2010 from a model with a single entity. Write some code to use the example in the document to run migrations programatically, then insert a entity using a LightSpeed unit of work and save changes. It fails with the following error: KeyTable generated identity was out of range. The key table may be empty. Ensure that the KeyTable table contains a row, and that the NextId value is at least 1. It is easily fixed by adding a single row to the KeyTable with value 1, but I was hoping that the migration will take care of it by seeding tables with the default values needed for id generation. Thanks, Werner
|
|
|
The KeyTable behaviour isn't related -- that's a limitation of a separate migration API. We agree that it would be less confusing to initialise the KeyTable with a typical seed -- note, however, that if there are existing tables in the database then you will need to amend the KeyTable seed to be higher than the highest ID currently in use. Beginning with tonight's nightly build we will generate migration code that seeds the KeyTable with the value 1. (NOTE: The behaviour of existing migration APIs will NOT be changed because users may already have added their own seeding code, which could fail, or worse still silently break, if we suddenly started inserting values when we did not before. What we will do is call a new overload.) Thanks for the feedback! |
|
|
Thanks for the explanation. Werner |
|