Typeorm: AbstractTable doesnt work in inherited classes

Created on 25 Dec 2016  路  3Comments  路  Source: typeorm/typeorm

Hi all!
I have problem with AbstractTable decorator. Error:
_MissingPrimaryColumnError: Entity "Post" 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._
Files:
BasePost.ts:

import {PrimaryGeneratedColumn, Column} from "typeorm";
import {AbstractTable} from "typeorm";

@AbstractTable()
export class BasePost {
    @PrimaryGeneratedColumn()
    id: number;

    @Column()
    title: string;
}

Post.ts:

import {Column, Table} from "typeorm";
import {BasePost} from "./BasePost";

@Table("post")
export class Post extends BasePost {
    @Column()
    text: string;
}

app.ts:

import "reflect-metadata";
import { createConnection } from "typeorm";
import { Post } from "./entities/Post";

createConnection({
  driver: {
    type: "postgres",
    host: "host",
    port: 7755,
    username: "postgres",
    password: "pass",
    database: "testdatabase"
  },
  entities: [
    Post
  ],
  autoSchemaSync: true
  }).then(connection => {
    console.log('Good!');
  })
  .catch(reason => {
    console.log(reason);
});

What is wrong?
NodeJS version: 7.3.0
Typescript version: 2.1.4
TypeORM version: 0.0.5

question

Most helpful comment

Please include BasePost in a list of your entities: [Post, BasePost]

All 3 comments

Please include BasePost in a list of your entities: [Post, BasePost]

@pleerock thanks a lot! :)

one star from you ;)

Was this page helpful?
0 / 5 - 0 ratings