Skip to content

Error creating full database script after migrations run #10

Open

Description

@roji

From @jdcrutchley on February 20, 2015 21:42

This only occurs if I've already run migrations and specify I want to create a full database creation script like so:

Database-Update -Script -SourceMigration $InitialDatabase

The error generated is:

object reference not set to an instance of an object

If I specify any other source migration besides $IntialDatabase it works properly. Also, if I first revert all the way to zero then ask for script, it runs fine. So this is my current workaround:

Database-Update -TargetMigration $InitialDatabase
Database-Update -Script
Database-Update

So there's a fine workaround, but it would be nice to be able to generate the script without reverting first.

Copied from original issue: npgsql/npgsql#497

Activity

  1. roji commented on May 12, 2016

    @roji
    MemberAuthor

    From @peterz11 on September 25, 2015 21:29

    I have confirmed this exact problem, using EF 6 and npgsql 2.2.7 for entity framework. By reverting to an empty database, this script will get generated. With migrations run, i also get the object null ref error. Here is more of the call stack:

    System.NullReferenceException: Object reference not set to an instance of an object.
    at Npgsql.NpgsqlMigrationSqlGenerator.Convert(IEnumerable1 operations) at Npgsql.NpgsqlMigrationSqlGenerator.Convert(IEnumerable1 operations)
    at Npgsql.NpgsqlMigrationSqlGenerator.Generate(IEnumerable1 migrationOperations, String providerManifestToken) at System.Data.Entity.Migrations.DbMigrator.GenerateStatements(IList1 operations, String migrationId)
    at System.Data.Entity.Migrations.Infrastructure.MigratorBase.GenerateStatements(IList`1 operations, String migrationId)
    at System.Data.Entity.Migrations.Infrastructure.MigratorScriptingDecorator.ScriptUpdate(String sourceMigration, String targetMigration)
    at System.Data.Entity.Migrations.Design.ToolingFacade.ScriptUpdateRunner.Run()
    at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
    at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
    at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
    at System.Data.Entity.Migrations.Design.ToolingFacade.ScriptUpdate(String sourceMigration, String targetMigration, Boolean force)
    at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
    at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
    Object reference not set to an instance of an object.

  2. xklonx commented on Oct 9, 2020

    @xklonx
    Contributor

    Made a fix for the error.
    Do you think we can make the logic similar to the one used for the sqlserver, i.e. get latest migration id and then wrap every migration into if blocks using anonymous blocks or something else so that such a script can update any version of the database?

  3. ghorbey commented on Feb 26, 2021

    @ghorbey

    Any idea if the PR will be reviewed and merged anytime soon?
    We use EntityFramework6.Npgsql and we need to generate the same script (With IF statements) that's generated for SQL Server. IT would be really appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions