Migration.cs empty

Topics: Customizing Orchard, Troubleshooting, Writing modules
Sep 20, 2013 at 3:04 PM
Edited Sep 20, 2013 at 3:06 PM
Dear all,

I'm currently developing my first project in Orchard and so far It's been quite nice. However, now I'm struggling to create my first module, which uses it's own models and has therefore it's own database.

I've gone trough this (http://t.co/vY3cuDLbPU) documentation, but I'm not able to resolve this error by myself.
After using "codegen datamigration <feature>"
the generated Migrations.cs is just empty. I've created the 2 needed classes, however It's just not creating a proper migration.

By empy I mean:
using System;
using System.Collections.Generic;
using System.Data;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.MetaData.Builders;
using Orchard.Core.Contents.Extensions;
using Orchard.Data.Migration;

namespace Orchard.Projekt{
    public class Migrations : DataMigrationImpl {

        public int Create() {


            return 1;
        }
    }
}
He're the classes
using System;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Records;
using System.ComponentModel.DataAnnotations;

namespace Orchard.Projekt.Model
{
    public class CupRecord : ContentPartRecord
    {
        public virtual string Name { get; set; }
        public virtual string Server { get; set; }
        public virtual Int32 Size { get; set; }
        public virtual DateTime StartDate { get; set; }
        public virtual DateTime SignUpFrom { get; set; }
        public virtual DateTime SignupTo { get; set; }
        public virtual Boolean Active { get; set; }
    }

    public class CupPart : ContentPart<CupRecord>
    {
        [Required]
        public string Name
        {
            get { return Record.Name; }
            set { Record.Name = value; }
        }

        [Required]
        public string Server
        {
            get { return Record.Server; }
            set { Record.Server = value; }
        }
       
        [Required]
        public Int32 Size
        {
            get { return Record.Size; }
            set { Record.Size = value; }
        }

        [Required]
        public DateTime StartDate{
            get { return Record.StartDate; }
            set { Record.StartDate = value; }
        }

        [Required]
        public DateTime SignupFrom
        {
            get { return Record.SignUpFrom; }
            set { Record.SignUpFrom = value; }
        }

        [Required]
        public DateTime SignupTo
        {
            get { return Record.SignupTo; }
            set { Record.SignupTo = value; }
        }

        [Required]
        public Boolean Active
        {
            get { return Record.Active; }
            set { Record.Active = value; }
        }
    }
}
What am I doing wrong? Do I need to do something special, as this is the first time that my module need's it's own database?

Thanks for your help.

Regards,
SantoDE
Coordinator
Sep 20, 2013 at 5:40 PM
If it's using its own database (don't see why it does, but eh), you can't use Orchard migrations.
Sep 20, 2013 at 6:46 PM
Edited Sep 20, 2013 at 6:49 PM
BertrandLeRoy wrote:
If it's using its own database (don't see why it does, but eh), you can't use Orchard migrations.
Thanks for the reply.

What do you mean by "it's own"? Do you mean e.g. the Orchard Default SQLite one? Why it's not able to use it? What's the purpose of Orchard Migrations then?

I thought, that If i write a module I can use the "default" db? What other opportunities I'd have?

I basically just have my own new module, and I need to use a database and data access within it. Sorry for being noobish, but I don't see why it shouldn't be possible.
Coordinator
Sep 20, 2013 at 6:49 PM
You're the one who said "it's own database", not me. This is totally confusing. What are you trying to do?
Sep 20, 2013 at 6:54 PM
Sorry for confusing you.

What I basically want to achieve:

I've written a new Orchard Module. Within this module, I need to access a database to write and read out of it. By "it's own" database, I mean the one you define while installing Orchard, so either a SQLite, MSSQL or what so ever.

I thought that I can use this already "installed" database to create new tables in it and aferwards write / read data out / into it.

Therefore I've created my models as mentioned within the documentation and I'm trying to get a proper Migration.cs generated, which is not working currently. I only get the empty default ones mentioned within my initial post.

Thanks for helping :)
Coordinator
Sep 20, 2013 at 7:45 PM
Much clearer now. You just have to write the actual code for the migration. Look at an existing one for a sample.
Sep 20, 2013 at 8:07 PM
Okay. But then I don't understand why there is an code generation feature? Or do I not understand it's aim?

I've written the migration.cs by myself, deactivated the feature and activated it again. Sholdn't the migration didn't got executed in this case? Cause I can't see my new tables.
Coordinator
Sep 20, 2013 at 8:13 PM
code generation is giving you scaffolding.

The migration is not going to run again because it thinks (with good reason) that it already did. You need to rewind the migration counter directly in the database, or reset your database.
Sep 20, 2013 at 8:17 PM
Ahhh okay.

Yeah, sounds logically. Will try to find the table where the counter is saved. Will report back afterwards :)
Sep 20, 2013 at 8:22 PM
Edited Sep 20, 2013 at 8:23 PM
Okay, it was set to 1. I've seted it to 0 and deactivated / activated it again. It's still zero and no migration executed. What am I lacking this time? I used the table Orchard_Framework_DataMigrationRecord and the row with the name of my module.
Coordinator
Sep 20, 2013 at 8:24 PM
Try to remove the record completely, then restart the app.
Sep 20, 2013 at 8:30 PM
You are my hero. I finally have my table. Thank you soooooo much!