Question

I have two C# projects, Model and ModelTest. Model consists of ActiveRecord objects (wrapper around Hibernate). In ModelTest I created a simple unit test:

[TestClass]
public class UnitTest1
{
    [TestInitialize]
    public void Init()
    {
        Model.Init();
        Model.CreateSchema();
    }

    [TestMethod]
    public void TestMethod1()
    {
    }
}

Model.Init() registers all types of assembly Model with ActiveRecord. Model.CreateSchema() wraps ActiveRecordStarter.CreateSchema(), which calls CreateSchema() of NHibernate.

This code works fine, if I run the unit test, but it fails if I "debug" the unit test. In debug mode, an exception occurs in CreateSchema():

NpgsqlException: 'ERROR: 42P01: table "user" does not exist'

The exception seems to be raised during the SQL call "drop table user cascade", which obviously fails if the database is empty before running the test. I assume the drop is sent always before creating a new table.

Does Npgsql behave differently in debug mode, regarding the outcome of a drop query?

Was it helpful?

Solution

I had the exact same problem as Tarnschaf -- SchemaUpdate.Create(...) would fail and the offending sql was drop table "tablename" cascade which resulted in the same "table does not exist" error mentioned above.

It turns out that one of the projects had an reference to a Nhibernate-related assembly that was no longer in the same location. I'm not sure why this didn't show up when the solution was cleaned & rebuilt. Removing all references from the project and re-adding them solved the problem (for me).

Just posting this in case it helps someone else down the road. The Nhibernate exception was less than helpful.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top