sequelize / sequelize-typescript

Decorators and some other features for sequelize
MIT License
2.79k stars 282 forks source link

How to create table without primaryKey #1092

Open RezaRahmati opened 3 years ago

RezaRahmati commented 3 years ago

Issue

I am trying to create a hyper-table in timescaleDb, instructions

When I try to run SELECT create_hypertable('conditions', 'time'); it gives me the below error

ERROR:  cannot create a unique index without the column "time" (used in partitioning)
SQL state: TS103

Based on this post seems table should not have a primary key to be able to become as hyper-table.

I wasn't able to config sequelize to prevent creating id (or PrimaryKey)

@Table({timestamps: false, tableName: "conditions"})
export class Conditions extends Model {
//   @Column({ type: DataType.UUIDV4, allowNull: true, primaryKey: false})
//   id: string;

  @Column({ type: DataType.DATE, allowNull: false})
  time: string;

  @Column({ type: DataType.TEXT, allowNull: false})
  location: number;

  @Column({ type: DataType.DATE, allowNull: false})
  temperature: number;

  @Column({ type: DataType.DATE, allowNull: true})
  humidity: number;
}

Not sure if it;s a defect or feature request (or something exists and I wasn't able to find it)

Versions

"sequelize": "^6.6.5", "sequelize-typescript": "^2.1.0" "typescript": "^4.3.5"

Issue type

Actual behavior

Expected behavior

Steps to reproduce

Related code

insert short code snippets here
Jchase2 commented 1 year ago

I was able to work around this by doing this:

@Column({ type: DataType.DATE, allowNull: false, primaryKey: true }) uptime!: string;

It seemed to work if I set the time field as the primary key.