Reputation: 193
I am fairly new to TypeOrm and I am trying to use it for a project but I am facing issue in generating migrations. I have a Postgres App running on my local at port 5432.
My Entity looks like this:
@Entity()
export class User {
@PrimaryGeneratedColumn()
id!: number;
@Index({ unique: true })
@Column('text', {nullable:true})
username!: string;
@Index({ unique: true })
@Column('text', {nullable:true})
@IsEmail()
email!: string;
@Index()
@Column('bool',{nullable:true, default: false})
emailVerified!: boolean;
@UpdateDateColumn()
@IsDate()
updateDate!: Timestamp;
@Column('text',)
about!: string;
};
and my OrmConfig looks like this
{
"entities": ["src/entity/*.js"],
"migrations": ["src/migration/*.js"],
"subscribers": ["src/subscriber/**/*.js"],
"cli": {
"migrationsDir": "src/migration",
"entitiesDir": "src/entities",
"subscribersDir": "src/subscriber"
},
"url": "postgres://@0.0.0.0:5432/nftme_dev",
"type": "postgres",
"synchronize": true
}
When I run:
yarn run typeorm migration:generate -n initial
It throws an error saying:
$ node_modules/.bin/typeorm migration:generate -n initial
No changes in database schema were found - cannot generate a migration. To create a new empty migration use "typeorm migration:create" command```
Upvotes: 1
Views: 7331
Reputation: 193
So I finally was able to nail this down after debugging it for a day.
So when I was using synchronize: true
option the schema was already created for my entities in the database and when I tried to generate it failed as there was nothing that changed.
I created a fresh db and tried to generate migrations and it worked.
Upvotes: 3
Reputation: 2815
TypeORM offers so many possibilities that it is easy to get lost in them. ;-)
You can modify the local database and generate migration files:
typeorm migration:generate -n UserMigration
You can modify entities and synchronize changes: (you need this)
Upvotes: 1