Migrations.cs - how to find the current version?

Topics: Administration, Core, Troubleshooting
Oct 23, 2012 at 1:51 PM

Hi, in file Migrations.cs for every Update-from<Version> method we specify a number that is increment every time. How orchard knows which is the last version?

Oct 23, 2012 at 2:05 PM

It's stored in the database. There is a migrations table.

select * from sys.tables where name like '%migration%' 

Oct 23, 2012 at 2:25 PM

I don't know if I was clear before, but what I need is to know where version of my custom module for Migrations.cs is kept?

I have run the query, I just replaced the name value with my module table name, a record is return but I cannot see anywhere the current migration version of my module. It should be showing the number 7.

--> Modules/MyCustomModule/Migrations.cs

namespace UserSubmissions {
    public class Migrations : DataMigrationImpl {

        public int Create() {
            return 1;

        public int UpdateFrom1() {          
            return 2;

        public int UpdateFrom2()
          return 3;

and so on... How orchard will know that the next time I will add another UpdateFrom to start from there?

Oct 23, 2012 at 2:41 PM
Edited Oct 23, 2012 at 3:18 PM

That query just gets you the name of the table where the migration versions are stored for each module. You have to then query that table to find your module's migration version. 

Oct 23, 2012 at 3:01 PM

State is kept in the table Orchard_Framework_DataMigrationRecord (may vary between tenants)

An example from the table is

Id    DataMigrationClass    Version
1    Orchard.Core.Settings.Migrations    4

Orchard uses a convention based approach to search in the Migrations file. Take a look at DataMigrationManager.cs - This is driver class for all migrations if you are interested.


Oct 23, 2012 at 7:46 PM

It worked, see below the queries that I run in order to view the different class migrations versions. I think it would be very helpful if you can add this to your documentation.


SELECT * FROM sys.tables WHERE name like '%migration%' ;

--Field Name: Orchard_Framework_DataMigrationRecord


select * from Orchard_Framework_DataMigrationRecord;

Oct 23, 2012 at 7:55 PM

Consider it done. In fact, this thread itself will make a great contribution - migrations and recipes look like awesome tools that are under-reported. Please keep sharing the results of your learning curve cuz that's the cutting edge that'll help others. thankx!