Stuck on module upgrade not working

Jan 12, 2011 at 1:39 AM

I am trying to author my own module, and while the learning curve was a little steep for what I wanted to do, I'm there finally, however, after completing my module development I decided that I wanted another property on my part Model and model record corresponding with it, that seems fine, and I added another method to my implementation of DataMigrationImpl that returns 2 and adds the column in question, however when I run the site I get an exception trying to map the record to the type and the new module upgrade code is never called.

Is there any way to remove that record and/or table from the database or to at least force the upgrade/migration method to run in the correct context either via code or with the command line?

Error: could not load an entity: [SH.MyTestModule.Models.MyTestModuleSettingsPartRecord#1][SQL: SELECT mytestmodu0_.Id as Id467_0_, mytestmodu0_.MyTestModuleSettingsKey as MyTestMo2_467_0_, mytestmodu0_.DomainName as DomainName467_0_, mytestmodu0_.UseAsyncTracking as UseAsync4_467_0_, mytestmodu0_.TrackOnAdmin as TrackOnA5_467_0_ FROM SH_MyTestModule_MyTestModuleSettingsPartRecord mytestmodu0_ WHERE mytestmodu0_.Id=?]

	public class Migrations : DataMigrationImpl {
public int Create() {
table => table
return 1;
public int UpgradeFrom1() {
table => table
return 2;
Jan 12, 2011 at 2:28 AM

You probably put the database in an inconsistent state at some point. How about zapping the database and starting over? One advantage of that is that you can get the right code into Create directly instead of having an Update method. By the way, it's "UpdateFrom1", not "UpgradeFrom1".

Jan 12, 2011 at 2:39 PM

Here's what ended up happening (I didn't want to nuke the DB just yet as I had already done so much work in configuring and setting up the site):

  1. I enabled the component that I was developing to test my settings views, etc.
  2. At the end of my development I added the additional property and migration method
  3. Starting getting the error
  4. I changed the method name that you pointed out (didn't know it actually mattered) and still no joy, was getting the error
  5. I had to disable the feature using the command line (which was more than helpful, great feature guys!)
  6. Once disabled the site was working again
  7. I removed the the additional property from my part model record type but left it in my part model
  8. Once I did that, I spun up the site again, enabled the feature and it worked (although it wasn't populating my new property in the model)
  9. Only after I did that, did I get a message stating that my component needed to be updated in the dashboard, which I did successfully
  10. I added the property back in, and now it is working

What is the intended migration or update path when it comes to components? Should I package and "install" or reinstall these components when there is a change such as this which obviously breaks the data model mappings? I would like to develop several components and contribute to the community but want to be sure these are stable and upgradeable in the future as I have updates and that I do it correctly so other people won't be faced with nuking thier database for thier website(s) as the only recourse to get the module working again.

Perhaps a new attribute type in the framework or core that could be used to decorate new attributes and thier corresponding db migration version number (in this case it would have been 2) so that NHibernate can ignore it if it's at a lower version, etc. when mapping the repository types from the underlying data.

From now on I will leave my web site and feature/theme and module development in seperate instances so I can nuke databases or other things without corrupting the configuration work I'm doing in my actual site instance of Orchard.


Jan 12, 2011 at 3:26 PM

I was only suggesting nuking the database because you were in development. You should never need to ask your users to do that.

Jan 12, 2011 at 3:38 PM
bertrandleroy wrote:

I was only suggesting nuking the database because you were in development. You should never need to ask your users to do that.

Fully understand, thanks for your help honestly. I just want to be sure that going forward I understand the correct way to make changes to existing data models such as adding new columns, etc... I think the real issue was that my data model class was updated "live" without the module actually being updated the way the application or end user would normally update it, just a dev roadblock, that's all.

Thanks again for your help!