Error: Index contains column that is missing in the entity - @Index isn't using column name from @Column

See original GitHub issue

With an entity like this:

@Entity()
@Index(["country","iso3","region","name","rei_name"], { unique: true })
export class BurdenRegion implements Region {

    @PrimaryColumn()
    @Column({ length: 56 })
    country?: string;

    @PrimaryColumn()
    @Column({ length: 6})
    iso3?: string;

    @PrimaryColumn()
    @Column({ length: 12})
    region?: string;

    @PrimaryColumn()
    @Column({ length: 56})
    name?: string;

    @PrimaryColumn()
    @Column({name:"rei_name",length: 5})
    reiName?: string;
}

I get the following error:

Index contains column that is missing in the entity: rei_name

I want rei_name to be called reiName in the entity, so I added the column name property

@Column({name:"rei_name",length: 5})

But it’s not being used. If I change the @Index to use the entity name like this:

@Index(["country","iso3","region","name","reiName"], { unique: true })

I get another error:

error: column BurdenRegion.reiName does not exist

So I’m not sure how to configure this properly?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
pleerockcommented, Sep 22, 2017

Actually BurdenRegion.reiName is correct one since Index decorator expects property names, not database column names. Adding indices expert - mr. @iz-iznogood

1reaction
iz-iznogoodcommented, Sep 24, 2017

Hi all

this is the proper declaration, it works like a charm

@Entity()
@Index(["country", "iso3", "region", "name", "reiName"], { unique: true })
export class BurdenRegion /* implements Region */ {

  @PrimaryColumn({ length: 56 })
  country?: string;

  @PrimaryColumn({ length: 6 })
  iso3?: string;

  @PrimaryColumn({ length: 12 })
  region?: string;

  @PrimaryColumn({ length: 56 })
  name?: string;

  @PrimaryColumn({ name: "rei_name", length: 5 })
  reiName?: string;
}

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create a unique index containing multiple fields where ...
When i generate this entity and create the sql table (without the index) i see player_id as one of the columns. But it...
Read more >
Tune nonclustered indexes with missing index suggestions
Returns detailed information about a missing index; for example, it returns the name and identifier of the table where the index is missing,...
Read more >
Indexing and selecting data - Pandas
If a column is not contained in the DataFrame, an exception will be raised. ... pandas will raise a KeyError if indexing with...
Read more >
Secondary indexes | Cloud Spanner
The query processor retrieves these columns by joining the index and the base table. To avoid this extra join, use a STORING clause...
Read more >
13.1.20 CREATE TABLE Statement - MySQL :: Developer Zone
If you use quoted identifiers, quote the database and table names ... In other cases, you must declare indexed columns as NOT NULL...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found