PostgreSQL ERROR: 42P01: relation “[Table]” does not exist

前端 未结 3 1673
灰色年华
灰色年华 2021-02-13 17:27

I\'m having this strange problem using PostgreSQL 9.3 with tables that are created using qoutes. For instance, if I create a table using qoutes:

create table \"T         


        
3条回答
  •  孤独总比滥情好
    2021-02-13 18:16

    While using npg package as your data store ORM you are expecting the ORM framework (Entity Framework in our case) to generate the sql statement you might face a PostgreSQL exception the relation 'Table Name' does not exist

    Either the table is not created or the generated SQL statement is missing something. Try to debug using visual studio you will see that the schema name is not leading the table name

    SELECT "ID", "Name", "CreatedBy", "CreatedDate" 
    FROM "TestTable"; 
    

    while PostgreSQL is expecting the schema name. Resolution is in the DBContext class override the OnModelCreating method and add modelBuilder.HasDefaultSchema("SchemaName"); and execute the base constructor which should look like the following

    protected override void OnModelCreating(ModelBuilder modelBuilder)   {             
      modelBuilder.HasDefaultSchema("PartyDataManager");                  
      base.OnModelCreating(modelBuilder);         
    }
    

提交回复
热议问题