Skip to content

NH-3733 - MySQL Schema Update Doesn't Work #1331

@nhibernate-bot

Description

@nhibernate-bot

ergatech created an issue — 31st October 2014, 15:37:12:

I can update schema use SchemaUpdate on SQLSever 2012 but I can not update schema on MySQL with same code. I get Exception "'CONSTRAINT_NAME' colum .....".

I need schema name on mapping object. Example in attachment.


Oskar Berggren added a comment — 2nd November 2014, 18:47:34:

What is the error? I think we can at least expect the full error message in the issue report. What is the claimed bug (what does NH do wrong)? My time is limited and I don't want to spend it having to guess what you want.


ergatech added a comment — 8th November 2014, 10:03:47:

Dear Oscar;

I created a test case for you and this case in attachment. But no problem for me I can write detail in here.

NH Usage :

var config = Fluently.Configure()
                .Database(MySQLConfiguration.Standard.ConnectionString("Server=127.0.0.1;Port=3306;Uid=root;Pwd =xxxx")
                .Dialect<MySQL5Dialect>()
                .Driver<MySqlDataDriver>()
                .ShowSql()
                .FormatSql())
                .Mappings(x=>x.FluentMappings.AddFromAssemblyOf<Contact>())
                .BuildConfiguration();
            
            var updater = new SchemaUpdate(config);
            updater.Execute(true,true);

I have two database (Master and Detail). I mapping objects with Schema (FluentNhibernate with ClassMap class)

public class ContactMap : ClassMap<Contact>
{
    public ContactMap()
    {
        Table("test_tb_contact");
        Schema("nhibernate_test");
        Id(x => x.ID, "ID").GeneratedBy.Identity();
        Map(x => x.FirstName, "FirstName");
        Map(x => x.LastName, "LastName");
        Map(x => x.Gender, "Gender");
        Map(x => x.d1, "d1");
        Map(x => x.d2, "d2");
        Map(x => x.d3, "d3");
    }
}

My generated CreateSQL

create table nhibernate_test.test_tb_contact (
       ID BIGINT NOT NULL AUTO_INCREMENT,
       FirstName VARCHAR(255),
       LastName VARCHAR(255),
       Gender VARCHAR(255),
       d1 VARCHAR(255),
       d2 VARCHAR(255),
       d3 VARCHAR(255),
       primary key (ID)
    )

After I added a new field d4

My Mapping :

public class ContactMap : ClassMap<Contact>
{
    public ContactMap()
    {
        Table("test_tb_contact");
        Schema("nhibernate_test");
        Id(x => x.ID, "ID").GeneratedBy.Identity();
        Map(x => x.FirstName, "FirstName");
        Map(x => x.LastName, "LastName");
        Map(x => x.Gender, "Gender");
        Map(x => x.d1, "d1");
        Map(x => x.d2, "d2");
        Map(x => x.d3, "d3");
        Map(x => x.d4, "d4");
    }
}

NHibernate not update schema and Console write "'CONSTRAINT_NAME' sütunu, tablosuna ait değil." this message is turkish. Maybe english translate "'CONSTRAINT_NAME' column, does not belong this table." but Nhibernate must do generate ALTER Script.

If you run example in attachment you can see this error.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions