3

Does anybody know how to add an unique constraint to ext_tables.sql without creating problems like TYPO3 wanting to re-generate it every time you use the Database analyzer?

Example:

CREATE TABLE tableName(
  CONSTRAINT unique_iban UNIQUE (iban) 
)

CREATE TABLE tableName(
  iban varchar(255) DEFAULT '' NOT NULL UNIQUE 
)

With both ways the database analyzer wants to create the constraints, even if they are already there.

First one additionally creates an error when you execute it:

Error: Duplicate key name 'unique_iban'

Second one creates one new constraint every time you hit execute:

ALTER TABLE tableName DROP KEY iban
ALTER TABLE tableName DROP KEY iban_2

etc.

andreas
  • 16,357
  • 12
  • 72
  • 76
Aljoscha
  • 306
  • 3
  • 13

1 Answers1

7

This worked (thanks to Christian Müller):

CREATE TABLE tableName(
  iban varchar(255) DEFAULT '' NOT NULL,
  UNIQUE KEY iban (iban)
)
Aljoscha
  • 306
  • 3
  • 13