Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9219015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:00:04+00:00 2026-06-18T03:00:04+00:00

When using SchemaUpdate() to export a mapped class with auto-incremented id to a PostgreSQL

  • 0

When using SchemaUpdate() to export a mapped class with auto-incremented id to a PostgreSQL server the following exception is thrown:
“ERROR: 42P07: relation “seq_wuf” already exists”.

The exception is thrown because the table and sequence really exist in the server, but I would expect for SchemaUpdate() to ignore the already existing sequence.

Mapping table

public class CategoryMap : ClassMap<Category>
{
    public static string tableName = "miao";
    public CategoryMap()
    {
        SchemaAction.Export();
        Table(tableName);
        Id(x => x.Id).GeneratedBy.Sequence("SEQ_" + tableName);
        Map(x => x.Name).Column("Category")
                .CustomType("String")
                .Access.Property()
                .Generated.Never()
                //.CustomSqlType("nvarchar(50)")  // <----
                .Not.Nullable()
                .Length(50); ;
        Map(x => x.Description);
    }
}

Export Schema:

  FluentConfiguration config = Fluently.Configure();
        config
        .Database(PostgreSQLConfiguration
        .Standard
        .ConnectionString(connStringPosgtgres))
        .Mappings(m => m.FluentMappings.Add(typeof (CategoryMap)))
        .ExposeConfiguration(UpdateSchema)
        .BuildConfiguration();

SchemaUpdate()

private static void CreateSchema(Configuration cfg)
    {
        var schemaExport = new SchemaExport(cfg);
        schemaExport.Drop(false, true);
        schemaExport.Create(false, true);
    }     

Thanks,
Yuval

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:00:07+00:00Added an answer on June 18, 2026 at 3:00 am

    I found out why this happens.
    Basically, while ScemaUpdate can create the auto ID sequence, it can’t check if the sequence exists in the DB, and therefore tries to recreate an existing object prompting the error message.

    This code is used by NHibernate to check for the sequance (src: https://github.com/nhibernate/nhibernate-core/blob/master/src/NHibernate/Dialect/Schema/AbstractDataBaseSchema.cs).
    I tried toying with it for a while and also couldn’t retrieve sequnces from it.

    public virtual DataTable GetTables(string catalog, string schemaPattern, string 
    tableNamePattern, string[] types){
    var restrictions = new[] { catalog, schemaPattern, tableNamePattern }; 
    return connection.GetSchema("Tables", restrictions);\
    }
    

    Yuval.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the DateTime class, if I try to run the following code: $mydate =
I tried using the following query: Query q = getPersistenceManager().newQuery( getPersistenceManager().getExtent(ICommentItem.class, false) ); but
Using SQL Server 2008 R2 we are looking for a way to select the
Using Microsoft SQL Server 2005, is there any way to see when a table
Using getDefinitionByName I am consistently getting the error saying it is not defined (as
Using the following as an example (with $db being a previously created database connection
Using Tsql, how can I find out when MS SQL server was installed?
Using this code, the following execution yields strange results: C 100 R W The
I am trying to Update Schema on SQL Server CE 3.5 using Active Record
using this code: Java Server side: ... out = new PrintWriter(this.client.getOutputStream(), true); ... public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.