Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem For Rename Column With Keep Rows in Sequelize #1700

Open
kasrakhamesi opened this issue Nov 8, 2023 · 0 comments
Open

Problem For Rename Column With Keep Rows in Sequelize #1700

kasrakhamesi opened this issue Nov 8, 2023 · 0 comments

Comments

@kasrakhamesi
Copy link

kasrakhamesi commented Nov 8, 2023

Hi,I have table with 5 column and 1000 row, I want rename second column from imageUrl to slug for example.
and I want sequelize do not delete row in old column and don't want create new column
only I want rename column with all rows.
but in this code

import { Post } from '/post/entities/post.entity';
import { Module } from '@nestjs/common';

import { SequelizeModule } from '@nestjs/sequelize';

@module({
imports: [
SequelizeModule.forRoot({
dialect: 'mysql',
host: host,
port: port,
username: user,
password: pass,
database: db,
models: [Post ],
logging: true,
autoLoadModels: true,
synchronize: true,
sync: { alter: true },
}),
],
exports: [SequelizeModule],
})
export class DatabaseModule {}

Sequelize create new column with name slug and remove imageUrl and the row in imageUrl not transfered to slug column and slug column have empty or null row.

if I change : sync: { alter: true } to sync: { alter: { drop : false }}, Sequelize create new column with name slug and imageUrl exist too.

if I change : sync: { alter: true } to sync: { force :true }, Sequelize delete all rows

so How can fix that ?

Versions

"@nestjs/sequelize": "^9.0.2",
"sequelize": "^6.32.1",
"sequelize-typescript": "^2.1.5",
"@types/sequelize": "^4.28.15",
"typescript": "^4.7.4"

Framework

I Using nest.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant