-
-
Notifications
You must be signed in to change notification settings - Fork 95
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
Incorrect index creation order #151
Comments
I may have encountered the same problem. class User(BaseModel):
id = fields.IntField(pk=True)
name = fields.CharField(max_length=128, unique=True, description='名称')
password_hash = fields.CharField(max_length=128, description='密码哈希')
metas: fields.ReverseRelation['Meta']
class Meta(BaseModel):
id = fields.IntField(pk=True)
clip_title = fields.CharField(max_length=512, description='母本标题')
user: fields.ForeignKeyRelation['User'] = fields.ForeignKeyField('models.User', related_name='metas') I have migrated and uupgraded this model. class Meta(BaseModel):
id = fields.IntField(pk=True)
custom_id = fields.CharField(max_length=128, description='自定义ID') # add a field
clip_title = fields.CharField(max_length=512, description='母本标题')
user: fields.ForeignKeyRelation['User'] = fields.ForeignKeyField('models.User', related_name='metas')
class Meta:
unique_together = ('custom_id', 'user') # add unique key with new field The SQL generated by aerich is: -- upgrade --
ALTER TABLE `meta` ADD `custom_id` VARCHAR(128) NOT NULL COMMENT '自定义ID';
ALTER TABLE `meta` ADD UNIQUE INDEX `uid_meta_custom__2e5d62` (`custom_id`, `user_id`);
-- downgrade --
ALTER TABLE `meta` DROP INDEX `uid_meta_custom__2e5d62`;
ALTER TABLE `meta` DROP COLUMN `custom_id`; The order of sql is not correct, so upgrade cannot be applied. |
long2ice
added a commit
that referenced
this issue
Jun 1, 2021
Fixed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now I have a model like this:
I update it to this:
The sql file has an error: It will create unique index before create field.
The text was updated successfully, but these errors were encountered: