How to create table with EF core migration in Oracle?

0

I'm using Entity Framework Core and tried to create new table in existing schema in ORACLE database by using migration command PM> Update-Database -verbose but received following exception:

3F000: no schema has been selected to create in

Prior to execution Update-Databse I successfully created Migration object by calling PM> Add-Migration InitialCreate -verbose command. Full output:

PM> Add-Migration InitialCreate -verbose
Using project 'TestMigration'.
Using startup project 'TestMigration'.
Build started...
Build succeeded.
C:\Program Files\dotnet\dotnet.exe exec --depsfile C:\Users\shimont\source\repos\TestMigration\TestMigration\bin\Debug\net5.0\TestMigration.deps.json --additionalprobingpath C:\Users\shimont\.nuget\packages --runtimeconfig C:\Users\shimont\source\repos\TestMigration\TestMigration\bin\Debug\net5.0\TestMigration.runtimeconfig.json C:\Users\shimont\.nuget\packages\microsoft.entityframeworkcore.tools\5.0.3\tools\netcoreapp2.0\any\ef.dll migrations add InitialCreate --json --verbose --no-color --prefix-output --assembly C:\Users\shimont\source\repos\TestMigration\TestMigration\bin\Debug\net5.0\TestMigration.dll --startup-assembly C:\Users\shimont\source\repos\TestMigration\TestMigration\bin\Debug\net5.0\TestMigration.dll --project-dir C:\Users\shimont\source\repos\TestMigration\TestMigration\ --language C# --working-dir C:\Users\shimont\source\repos\TestMigration --root-namespace TestMigration
Using assembly 'TestMigration'.
Using startup assembly 'TestMigration'.
Using application base 'C:\Users\shimont\source\repos\TestMigration\TestMigration\bin\Debug\net5.0'.
Using working directory 'C:\Users\shimont\source\repos\TestMigration\TestMigration'.
Using root namespace 'TestMigration'.
Using project directory 'C:\Users\shimont\source\repos\TestMigration\TestMigration\'.
Remaining arguments: .
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider in assembly 'TestMigration'...
Finding Microsoft.Extensions.Hosting service provider...
Using environment 'Development'.
Using application service provider from Microsoft.Extensions.Hosting.
Found DbContext 'MyDBcontext'.
Finding DbContext classes in the project...
Using context 'MyDBcontext'.
Finding design-time services for provider 'Npgsql.EntityFrameworkCore.PostgreSQL'...
Using design-time services from provider 'Npgsql.EntityFrameworkCore.PostgreSQL'.
Finding design-time services referenced by assembly 'TestMigration'...
Finding design-time services referenced by assembly 'TestMigration'...
No referenced design-time services were found.
Finding IDesignTimeServices implementations in assembly 'TestMigration'...
No design-time services were found.
Writing migration to 'C:\Users\shimont\source\repos\TestMigration\TestMigration\Migrations\20210225081805_InitialCreate.cs'.
Writing model snapshot to 'C:\Users\shimont\source\repos\TestMigration\TestMigration\Migrations\MyDBcontextModelSnapshot.cs'.
To undo this action, use Remove-Migration.
PM> Update-Database -verbose
Using project 'TestMigration'.
Using startup project 'TestMigration'.
Build started...
Build succeeded.
C:\Program Files\dotnet\dotnet.exe exec --depsfile C:\Users\shimont\source\repos\TestMigration\TestMigration\bin\Debug\net5.0\TestMigration.deps.json --additionalprobingpath C:\Users\shimont\.nuget\packages --runtimeconfig C:\Users\shimont\source\repos\TestMigration\TestMigration\bin\Debug\net5.0\TestMigration.runtimeconfig.json C:\Users\shimont\.nuget\packages\microsoft.entityframeworkcore.tools\5.0.3\tools\netcoreapp2.0\any\ef.dll database update --verbose --no-color --prefix-output --assembly C:\Users\shimont\source\repos\TestMigration\TestMigration\bin\Debug\net5.0\TestMigration.dll --startup-assembly C:\Users\shimont\source\repos\TestMigration\TestMigration\bin\Debug\net5.0\TestMigration.dll --project-dir C:\Users\shimont\source\repos\TestMigration\TestMigration\ --language C# --working-dir C:\Users\shimont\source\repos\TestMigration --root-namespace TestMigration
Using assembly 'TestMigration'.
Using startup assembly 'TestMigration'.
Using application base 'C:\Users\shimont\source\repos\TestMigration\TestMigration\bin\Debug\net5.0'.
Using working directory 'C:\Users\shimont\source\repos\TestMigration\TestMigration'.
Using root namespace 'TestMigration'.
Using project directory 'C:\Users\shimont\source\repos\TestMigration\TestMigration\'.
Remaining arguments: .
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider in assembly 'TestMigration'...
Finding Microsoft.Extensions.Hosting service provider...
Using environment 'Development'.
Using application service provider from Microsoft.Extensions.Hosting.
Found DbContext 'MyDBcontext'.
Finding DbContext classes in the project...
Using context 'MyDBcontext'.
Finding design-time services for provider 'Npgsql.EntityFrameworkCore.PostgreSQL'...
Using design-time services from provider 'Npgsql.EntityFrameworkCore.PostgreSQL'.
Finding design-time services referenced by assembly 'TestMigration'...
Finding design-time services referenced by assembly 'TestMigration'...
No referenced design-time services were found.
Finding IDesignTimeServices implementations in assembly 'TestMigration'...
No design-time services were found.
fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
      Failed executing DbCommand (59ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      CREATE TABLE "__EFMigrationsHistory" (
          "MigrationId" character varying(150) NOT NULL,
          "ProductVersion" character varying(32) NOT NULL,
          CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY ("MigrationId")
      );
Failed executing DbCommand (59ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE "__EFMigrationsHistory" (
    "MigrationId" character varying(150) NOT NULL,
    "ProductVersion" character varying(32) NOT NULL,
    CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY ("MigrationId")
);
Npgsql.PostgresException (0x80004005): 3F000: no schema has been selected to create in
   at Npgsql.NpgsqlConnector.<ReadMessage>g__ReadMessageLong|194_0(NpgsqlConnector connector, Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)
   at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
   at Npgsql.NpgsqlDataReader.NextResult()
   at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteNonQuery(Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteNonQuery()
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteNonQuery(RelationalCommandParameterObject parameterObject)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String connectionString, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String connectionString, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
  Exception data:
    Severity: ERROR
    SqlState: 3F000
    MessageText: no schema has been selected to create in
    Position: 14
    File: namespace.c
    Line: 494
    Routine: RangeVarGetCreationNamespace
3F000: no schema has been selected to create in

appsettings.json:

{
  "ConnectionStrings": {
    "MyDB": "Host=ls-30379697d1dc8c525de0af44815482283f4ef6b1.cdnopdufopsb.eu-central-1.rds.amazonaws.com;Database=companyName;Username=cdev;Password=aaaaaaaaaa"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*"
}

Program.cs:

 public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });
    }

Model:

  [Table("PostgresItem", Schema = "test")]
    public class MyModel
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Adddress { get; set; }
    }

DbContext:

using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace TestMigration
{
    public class MyDBcontext : DbContext
    {

        public MyDBcontext(DbContextOptions options) : base(options)
        {
        }

        public DbSet<MyModel> MyModelTable { get; set; }
    }
}

Stratup.cs:

 public void ConfigureServices(IServiceCollection services)
        {
            services.AddRazorPages();
            services.AddDbContext<MyDBcontext>(x => x.UseNpgsql(Configuration.GetConnectionString("MyDB")));
        }
c#
postgresql
oracle
entity-framework-core
entity-framework-migrations
asked on Stack Overflow Feb 25, 2021 by user1698581

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0