Is the a way to change the naming convention of constraints in OrmLite?

Constraint names on primary keys and default values are generated with random character sequences at the end to make them unique. If you delete the table and re-create it, the names don’t match the ones from the first time around.

This makes life difficult if you are using a database compare tool (e.g. redgate sql compare) to do migration scripts since user A’s db constraint names will be different than user B’s db constraint names.

Foreign key & index naming doesn’t add any random characters.

Is there a way to change the naming scheme so that the random sequences aren’t used?

That constraint name doesn’t look like it was created by OrmLite, which Dialect Provider are you using?

I’m using SqlServerDialect

OrmLite doesn’t generate the Constraint name for Primary Key’s, it only adds it to the Field Definition, e.g:

CREATE TABLE "MyTable" 
(
  "Id" INTEGER PRIMARY KEY AUTOINCREMENT, 
  "Name" VARCHAR(255) NULL 
);

To override the generated Create Table SQL you can inherit SqlServerOrmLiteDialectProvider in a custom Dialect Provider and override ToCreateTableStatement() and string replace the SQL Statement with your preferred CREATE TABLE SQL.

Ok, yeah I confirmed that SQL autogenerates the name when the CONSTRAINT [name] is not included in the table script. I’ll have to figure out a different way to deal with this.

CREATE TABLE "MyTable" 
(
  "Id" INTEGER CONSTRAINT [PK_MyTable] PRIMARY KEY AUTOINCREMENT, 
  "Name" VARCHAR(255) NULL 
);