Open ehdgua01 opened 3 years ago
Error raised after I removed duplicated M2M table(user_user_group_relation
)
I applied this SQL
-- upgrade --
CREATE TABLE IF NOT EXISTS `user_group` (
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
`name` VARCHAR(10) NOT NULL
) CHARACTER SET utf8mb4;;
CREATE TABLE IF NOT EXISTS `user_user_group_relation` (
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
`is_active` BOOL NOT NULL,
`user_id` INT NOT NULL,
`user_group_id` INT NOT NULL,
CONSTRAINT `fk_user_use_user_9a3f6327` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE,
CONSTRAINT `fk_user_use_user_gro_1ced338a` FOREIGN KEY (`user_group_id`) REFERENCES `user_group` (`id`) ON DELETE CASCADE
) CHARACTER SET utf8mb4;;
-- downgrade --
DROP TABLE IF EXISTS `user_user_group_relation`;
DROP TABLE IF EXISTS `user_group`;
And I add a new table with a new M2M field
class UserGroup(models.Model):
name = fields.CharField(max_length=10)
# new M2M field
operation_set = fields.ManyToManyField("models.Operation", related_name="usergroup_set")
class Meta:
table = "user_group"
# New table
class Operation(orm.AbstractBaseModel):
name = fields.CharField(max_length=255)
operation_id = fields.CharField(max_length=255)
description = fields.TextField()
class Meta:
table = "operation"
And I ran this command
poetry run aerich migrate
Finally, I got this error... 😢
Traceback (most recent call last):
File "/Users/A202006042/.virtualenvs/myproj/bin/aerich", line 8, in <module>
sys.exit(main())
File "/Users/A202006042/.virtualenvs/myproj/lib/python3.9/site-packages/aerich/cli.py", line 258, in main
cli()
File "/Users/A202006042/.virtualenvs/myproj/lib/python3.9/site-packages/click/core.py", line 1137, in __call__
return self.main(*args, **kwargs)
File "/Users/A202006042/.virtualenvs/myproj/lib/python3.9/site-packages/click/core.py", line 1062, in main
rv = self.invoke(ctx)
File "/Users/A202006042/.virtualenvs/myproj/lib/python3.9/site-packages/click/core.py", line 1668, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/A202006042/.virtualenvs/myproj/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/A202006042/.virtualenvs/myproj/lib/python3.9/site-packages/click/core.py", line 763, in invoke
return __callback(*args, **kwargs)
File "/Users/A202006042/.virtualenvs/myproj/lib/python3.9/site-packages/click/decorators.py", line 26, in new_func
return f(get_current_context(), *args, **kwargs)
File "/Users/A202006042/.virtualenvs/myproj/lib/python3.9/site-packages/aerich/cli.py", line 33, in wrapper
loop.run_until_complete(f(*args, **kwargs))
File "/Users/A202006042/.pyenv/versions/3.9.4/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "/Users/A202006042/.virtualenvs/myproj/lib/python3.9/site-packages/aerich/cli.py", line 91, in migrate
ret = await command.migrate(name)
File "/Users/A202006042/.virtualenvs/myproj/lib/python3.9/site-packages/aerich/__init__.py", line 115, in migrate
return await Migrate.migrate(name)
File "/Users/A202006042/.virtualenvs/myproj/lib/python3.9/site-packages/aerich/migrate.py", line 130, in migrate
cls.diff_models(cls._last_version_content, new_version_content)
File "/Users/A202006042/.virtualenvs/myproj/lib/python3.9/site-packages/aerich/migrate.py", line 214, in diff_models
table = change[0][1].get("through")
AttributeError: 'str' object has no attribute 'get'
@long2ice, Please help me 🙏🏿
我最近也遇到了这个问题,请问你解决了吗
Problem
Two tables have created when I add a new M2M field that through my custom table
Before.
After.
user_user_group_relation
table duplicated