tortoise / aerich

A database migrations tool for TortoiseORM, ready to production.
https://github.com/tortoise/aerich
Apache License 2.0
808 stars 91 forks source link

data lost after renamed the table name #232

Closed activa-media closed 2 years ago

activa-media commented 2 years ago

I am so sad I got data lost after renamed the table name : ( I saw the migration script, it dropped my old table. Is it like that? or any way to prevent data lost?

aerich==0.6.2 python: 3.9.10

long2ice commented 2 years ago

First, I'm sorry to hear that. You should always review migration sql first. And what's the models change before and after?

activa-media commented 2 years ago

I was trying to change the class name and table name, like below

# before
class my_table(models.Model):
    .....
    class Meta:
        table = 'my_table'

# after
class my_table_new(models.Model):
    .....
    class Meta:
        table = 'my_table_new'

or is it better not to drop the old table? maybe pass some parameters to not generate drop script?

long2ice commented 2 years ago

The point is the class name, if you change table name only but not class name, which may be work fine. If not, aerich don't know which is a new model or a old model.

activa-media commented 2 years ago

@long2ice Thank your for your reply, and I will note on this.