Closed hoonoh closed 3 years ago
It also occurs in mysql
.
It would be great if we could manually name the constraint
on foreign keys, unique etc on the decorator level, for example @PrimaryGeneratedColumn({constraint: 'User_primary_key'}
Also it would be more amazing to have a default strategy, better than FK_xxxx
etc, to mimic the above, for example ${entity}_${column$}_reason
, like 'user_id_primaryKey' or
user_name_unique` or `` 'user_id_foreignKey_references_user_id' etc.
This will allow typeorm to properly document the DB schema and interoperability with other tools that use or generate such schema details.
Is there any workaround for this issue?
Instead, I could use @Index
:
@Index(`email_uniq_index`, ['email'], { unique: true })
But it does not generate a constraint :(
One workaround, if you need to get the name of the constraint:
const tableName = connection.getMetadata(Entity).tableName
const constraintName = connection.namingStrategy.uniqueConstraintName(
tableName,
['columnName']
)
Is this issue still happening?
Yes it's still there. Typeorm ver 0.2.25, pg ver. 8.3.0
this issue is still happening :(
@Unique("unique-email", ["email"])
generates queries:
ALTER TABLE "users" ADD CONSTRAINT "UQ_97672ac88f789774dd47f7c8be3" UNIQUE ("email")
This issue still exists with TypeORM 0.3.17 and Postgres 15.x.
I encounter the exact same issue as detailed in https://github.com/typeorm/typeorm/issues/8494#issuecomment-1545606498.
Issue type:
[ ] question [x] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ]
cordova
[ ]mongodb
[ ]mssql
[ ]mysql
/mariadb
[ ]oracle
[x]postgres
[ ]sqlite
[ ]sqljs
[ ]react-native
TypeORM version:
[x]
latest
[ ]@next
[ ]0.x.x
(or put your version here)Steps to reproduce or a small repository showing the problem:
Naming unique constraints with
@Unique
decorator works for constraints with multiple columns but for constraints with single column it generates random name.generates queries: