bug report - MissingPrimaryColumnError: Entity "Provider" does not have a primary column.
See original GitHub issueIssue type:
[ ] question [x] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] mssql
[x] mysql
/ mariadb
[ ] oracle
[ ] postgres
TypeORM version:
[ ] latest
[ ] @next
[ ] 0.x.x
(or put your version here)
I have these two entities:
'use strict';
import {Column, Entity, Index, PrimaryColumn, PrimaryGeneratedColumn} from "typeorm";
@Entity()
@Index(["emailPrimary"], { unique: true })
@Index(["emailSecondary"], { unique: true })
@Index(["companyName"], { unique: true })
export class Provider {
@PrimaryGeneratedColumn()
id: number;
@Column()
companyName: string;
@Column()
pin: string; // 6 digit pin
@Column()
emailPrimary: string;
@Column()
emailSecondary: string;
@Column()
phonePrimary: string;
@Column()
phoneSecondary: string;
}
//////////////////////////////////////////////////////////
'use strict';
import {Column, Entity, Index, JoinColumn, OneToOne, PrimaryGeneratedColumn} from "typeorm";
import {Provider} from "./provider";
@Entity()
@Index(["phone"], { unique: true })
export class ProviderHardwarePhoneNumbers {
@PrimaryGeneratedColumn()
id: number;
@OneToOne(t => Provider)
@JoinColumn()
provider: Provider;
@Column()
phone: string; // 6 digit pin
}
if I run my project with synchronize:true
(node:28701) [DEP0095] DeprecationWarning: timers.enroll() is deprecated. Please use setTimeout instead.
(node:28701) [DEP0096] DeprecationWarning: timers.unenroll() is deprecated. Please use clearTimeout instead.
unhandledRejection { MissingPrimaryColumnError: Entity "Provider" does not have a primary column. Primary column is required to have in all your entities. Use @PrimaryColumn decorator to add a primary column to your entity.
at new MissingPrimaryColumnError (/home/oleg/WebstormProjects/moove/moove-api-mariadb/node_modules/typeorm/error/MissingPrimaryColumnError.js:18:28)
at EntityMetadataValidator.validate (/home/oleg/WebstormProjects/moove/moove-api-mariadb/node_modules/typeorm/metadata-builder/EntityMetadataValidator.js:51:19)
at /home/oleg/WebstormProjects/moove/moove-api-mariadb/node_modules/typeorm/metadata-builder/EntityMetadataValidator.js:41:74
at Array.forEach (<anonymous>)
at EntityMetadataValidator.validateMany (/home/oleg/WebstormProjects/moove/moove-api-mariadb/node_modules/typeorm/metadata-builder/EntityMetadataValidator.js:41:25)
at Connection.buildMetadatas (/home/oleg/WebstormProjects/moove/moove-api-mariadb/node_modules/typeorm/connection/Connection.js:515:33)
at Connection.<anonymous> (/home/oleg/WebstormProjects/moove/moove-api-mariadb/node_modules/typeorm/connection/Connection.js:162:30)
at step (/home/oleg/WebstormProjects/moove/moove-api-mariadb/node_modules/typeorm/connection/Connection.js:32:23)
at Object.next (/home/oleg/WebstormProjects/moove/moove-api-mariadb/node_modules/typeorm/connection/Connection.js:13:53)
at fulfilled (/home/oleg/WebstormProjects/moove/moove-api-mariadb/node_modules/typeorm/connection/Connection.js:4:58)
name: 'MissingPrimaryColumnError',
message:
'Entity "Provider" does not have a primary column. Primary column is required to have in all your entities. Use @PrimaryColumn decorator to add a primary column to your entity.' }
here is my project’s config:
module.exports = {
type: "mariadb",
host: process.env.moove_db_host,
port: process.env.moove_db_port,
username: process.env.moove_db_username,
password: process.env.moove_db_password,
database: process.env.moove_database_name,
synchronize: true,
logging: false,
entities: [
"dist/entity/**/*.js"
],
migrations: [
"dist/migration/**/*.js"
],
subscribers: [
"dist/subscriber/**/*.js"
],
cli: {
"entitiesDir": "src/entity",
"migrationsDir": "src/migration",
"subscribersDir": "src/subscriber"
}
};
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
It's possible, create a table without primary key in TypeOrm?
Ciao, no you can't because its required for entities to have a primary column in terms of ORM because most of ORM operations...
Read more >Issue Tracker - Google Developers
An issue in Google Issue Tracker is a bug report, feature request, change request or process workflow item that a user wants to...
Read more >TypeORM - Entity - Tutorialspoint
An entity is a collection of fields and associated database operations. It is used to map database table and its fields with the...
Read more >typeorm - npm
Creating a primary column. Each entity must have at least one primary key column. This is a requirement and you can't avoid it....
Read more >How to Report Bugs Effectively - PowerWorld
Anybody who has written software for public use will probably have received at least one bad bug report. Reports that say nothing ("It...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For people who come here with the same problem, that solved for me. I’ve deleted the ‘dist’ folder and ran
npm run build
.After that, it worked again.
@pleerock np, I made a simpler repro and the problem didn’t exist. What was happening is I had an old
.js
file in the target directory.rm -rf dist/* && tsc
solved it…annoying problem, but has to do with tsc not typeorm. the problem happens when you create/delete/rename .ts files.