Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Down with a Sequence generated in incorrect order #28349

Closed
pdevito3 opened this issue Jun 30, 2022 · 0 comments · Fixed by #28361
Closed

Down with a Sequence generated in incorrect order #28349

pdevito3 opened this issue Jun 30, 2022 · 0 comments · Fixed by #28361
Assignees
Labels
area-migrations closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Milestone

Comments

@pdevito3
Copy link

File a bug

Include your code

I have a config like this:

        modelBuilder.HasSequence<long>(Consts.DatabaseSequences.ConferenceOrderNoSequence)
            .StartsAt(10000000) /
            .IncrementsBy(1);

// .....

    public void Configure(EntityTypeBuilder<Conference> builder)
    {
        builder.Property(o => o.OrderNo)
            .HasDefaultValueSql($"concat('CONF', nextval('\"{Consts.DatabaseSequences.ConferenceOrderNoSequence}\"'))")
            .IsRequired();
    }

that generates a migration like this

        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateSequence(
                name: "ConferenceOrderNumbers",
                startValue: 10000000L);

            migrationBuilder.AddColumn<string>(
                name: "order_no",
                schema: "event",
                table: "event",
                type: "text",
                nullable: false,
                defaultValueSql: "concat('CONF', nextval('\"ConferenceOrderNumbers\"'))");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {            
            migrationBuilder.DropSequence(
                name: "ConferenceOrderNumbers");

            migrationBuilder.DropColumn(
                name: "order_no",
                schema: "event",
                table: "event");
        }

I can easily resolve this manually by switching the order to this, but knowing and remembering to do that isn't ideal:

        protected override void Down(MigrationBuilder migrationBuilder)
        {            
            migrationBuilder.DropColumn(
                name: "order_no",
                schema: "event",
                table: "event");

            migrationBuilder.DropSequence(
                name: "ConferenceOrderNumbers");
        }

Include stack traces

Include the full exception message and stack trace for any exception you encounter.

Use triple-tick fences for stack traces. For example:

DETAIL: Detail redacted as it may contain sensitive data. Specify 'Include Error Detail' in the connection string to include this information.
   at Npgsql.Internal.NpgsqlConnector.<ReadMessage>g__ReadMessageLong|211_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.MigrationCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecuteNonQuery(IEnumerable`1 migrationCommands, IRelationalConnection connection)
   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: 2BP01
    MessageText: cannot drop sequence "ConferenceOrderNumbers" because other objects depend on it
    Detail: Detail redacted as it may contain sensitive data. Specify 'Include Error Detail' in the connection string to include this information.
    Hint: Use DROP ... CASCADE to drop the dependent objects too.
    File: dependency.c
    Line: 1195
    Routine: reportDependentObjects
2BP01: cannot drop sequence "ConferenceOrderNumbers" because other objects depend on it

Include provider and version information

EF Core version:
Database provider: postgres
Target framework: .NET 6
Operating system: MacOS 12.4
IDE: Rider 22.1

@roji roji self-assigned this Jul 2, 2022
roji added a commit to roji/efcore that referenced this issue Jul 2, 2022
@roji roji added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jul 2, 2022
roji added a commit to roji/efcore that referenced this issue Jul 2, 2022
@ajcvickers ajcvickers added this to the 7.0.0 milestone Jul 5, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.0, 7.0.0-preview7 Jul 7, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.0-preview7, 7.0.0 Nov 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-migrations closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants