Error on Referencing a relation column in Unique constraint.
See original GitHub issueI’m trying to add a Unique
constraint with 2 columns where one column is the id
column of the same entity and second column is the id
column of the @ManyToOne
relation column.
This isn’t working and TypeORM throws error:
Error: Index contains column that is missing in the entity: albumId
Here’s my class:
@Entity()
@Unique('test_index', ['id', 'albumId'])
export class Photo {
@PrimaryGeneratedColumn()
id: number;
@ManyToOne(type => Album, album => album.photos)
album: Album;
What I am trying to achieve is to create a Unique
index on combination of 2 columns where 1 column (albumId
) is supposedly the foreign key column generated by TypeORM.
What’s the correct way to reference the albumId
column in Unique
index?
I also tried @Unique('test_index', ['id', 'album.albumId'])
but that didn’t work either.
Thanks!
Issue type:
[ x] question [ ] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[x] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[x] latest
[ ] @next
[ ] 0.x.x
(or put your version here)
Steps to reproduce or a small repository showing the problem:
Issue Analytics
- State:
- Created 4 years ago
- Comments:6
Top GitHub Comments
Just exclude the
Id
part.You should declare your
albumId
column (it doesn’t interfere on the relation).You can declare it as private if you are not going to use it: