Skip to content

Schema does not match when using a custom unique constraint #2925

Closed Answered by simolus3
Sobotkama asked this question in Q&A
Discussion options

You must be logged in to vote

You could add an index to the list of schema entities drift expects in the database by overriding this getter in the database class:

  @override
  List<DatabaseSchemaEntity> get allSchemaEntities => [
        ...super.allSchemaEntities,
        Index('UQ_PhysicalDevice',
            'CREATE UNIQUE INDEX IF NOT EXISTS UQ_PhysicalDevice ON "physical_devices" ("identifier", COALESCE("manufacturer", \'\'), "model_name");')
      ];

This will also make the migrator create the index with createAll(), so you need no additional custom statements.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Sobotkama
Comment options

@simolus3
Comment options

@Sobotkama
Comment options

Answer selected by Sobotkama
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants