Comments (21)
Yes, this need some update.
from aerich.
Supported in ce8c0b1 , just try.
from aerich.
@long2ice
I clone your new file migration.py
and cover in site-packages
.
I tired delete all table and initialization again, but nothing to change the ForeignKey Still there.
from aerich.
You can upgrade by pip install git+https://github.com/tortoise/aerich.git@dev
, delete old files and delete records in database, then try again.
from aerich.
OK, I'll try it later
from aerich.
I upgrade and delete records by your way by it's real nothing to change, fk still there @long2ice
from aerich.
See change sql what it is, and migrate depends on old_model.py
, which should be different from your current models.
from aerich.
I change one filed's db_constraint
to True, and run aerich migrate
then it raise error :
Traceback (most recent call last):
File "/home/connor/.virtualenvs/blog/bin/aerich", line 8, in <module>
sys.exit(main())
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/aerich/cli.py", line 241, in main
cli()
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/aerich/cli.py", line 28, in wrapper
return asyncio.run(f(*args, **kwargs))
File "/usr/local/lib/python3.8/asyncio/runners.py", line 43, in run
return loop.run_until_complete(main)
File "/usr/local/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/aerich/cli.py", line 82, in migrate
ret = await Migrate.migrate(name)
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/aerich/migrate.py", line 124, in migrate
cls.diff_models(diff_models, app_models)
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/aerich/migrate.py", line 227, in diff_models
cls.diff_model(old_models.get(new_model_str), new_model, upgrade)
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/aerich/migrate.py", line 346, in diff_model
if old_field.db_constraint and not new_field.db_constraint:
AttributeError: 'ForeignKeyFieldInstance' object has no attribute 'db_constraint'
from aerich.
Are you Chinese? How about communicate in Chinese, my English is too poor
from aerich.
升级tortoise
from aerich.
升级 tortoise-orm 后重新执行, 然后就出现了新的错误:
Traceback (most recent call last):
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/aiomysql/connection.py", line 598, in _read_bytes
data = await self._reader.readexactly(num_bytes)
File "/usr/local/lib/python3.8/asyncio/streams.py", line 723, in readexactly
await self._wait_for_data('readexactly')
File "/usr/local/lib/python3.8/asyncio/streams.py", line 517, in _wait_for_data
await self._waiter
RuntimeError: Task <Task pending name='Task-4' coro=<migrate() running at /home/connor/.virtualenvs/blog/lib/python3.8/site-packages/aerich/cli.py:82> cb=[_run_until_complete_cb() at /usr/local/lib/python3.8/asyncio/base_events.py:184]> got Future <Future pending> attached to a different loop
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/tortoise/backends/mysql/client.py", line 188, in execute_query
await cursor.execute(query, values)
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/aiomysql/cursors.py", line 239, in execute
await self._query(query)
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/aiomysql/cursors.py", line 457, in _query
await conn.query(q)
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/aiomysql/connection.py", line 428, in query
await self._read_query_result(unbuffered=unbuffered)
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/aiomysql/connection.py", line 622, in _read_query_result
await result.read()
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/aiomysql/connection.py", line 1105, in read
first_packet = await self.connection._read_packet()
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/aiomysql/connection.py", line 561, in _read_packet
packet_header = await self._read_bytes(4)
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/aiomysql/connection.py", line 599, in _read_bytes
except asyncio.streams.IncompleteReadError as e:
AttributeError: module 'asyncio.streams' has no attribute 'IncompleteReadError'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/connor/.virtualenvs/blog/bin/aerich", line 8, in <module>
sys.exit(main())
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/aerich/cli.py", line 241, in main
cli()
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/aerich/cli.py", line 28, in wrapper
return asyncio.run(f(*args, **kwargs))
File "/usr/local/lib/python3.8/asyncio/runners.py", line 43, in run
return loop.run_until_complete(main)
File "/usr/local/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/aerich/cli.py", line 82, in migrate
ret = await Migrate.migrate(name)
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/aerich/migrate.py", line 132, in migrate
return await cls._generate_diff_sql(name)
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/aerich/migrate.py", line 104, in _generate_diff_sql
version = await cls.generate_version(name)
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/aerich/migrate.py", line 94, in generate_version
last_version_num = await cls._get_last_version_num()
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/aerich/migrate.py", line 85, in _get_last_version_num
last_version = await cls.get_last_version()
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/aerich/migrate.py", line 56, in get_last_version
return await Aerich.filter(app=cls.app).first()
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/tortoise/queryset.py", line 797, in _execute
instance_list = await self._db.executor_class(
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/tortoise/backends/base/executor.py", line 123, in execute_select
_, raw_results = await self.db.execute_query(query.get_sql())
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/tortoise/backends/mysql/client.py", line 37, in translate_exceptions_
return await func(self, *args)
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/tortoise/backends/mysql/client.py", line 193, in execute_query
return cursor.rowcount, []
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/tortoise/backends/base/client.py", line 300, in __aexit__
await self.pool.release(self.connection)
File "/home/connor/.virtualenvs/blog/lib/python3.8/site-packages/aiomysql/pool.py", line 215, in release
fut = self._loop.create_task(self._wakeup())
File "/usr/local/lib/python3.8/asyncio/base_events.py", line 429, in create_task
self._check_closed()
File "/usr/local/lib/python3.8/asyncio/base_events.py", line 508, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
sys:1: RuntimeWarning: coroutine 'Pool._wakeup' was never awaited
from aerich.
检查数据库连接
from aerich.
数据库的连接是没有问题的, 我测试了一下删除文件,重新初始化, 没有问题, 连接是成功的, 也成功的进行了表的创建, 随意更改一个字段的参数后,执行 aerich migrate
就出现了这个问题
from aerich.
那有点奇怪
from aerich.
我现在的问题是, 无论做什么都无法进行 migrate的操作, 但是 外键依旧存在的问题解决了, 我刚才看了一眼数据库, 重新初始化后的表结构里已经没有外键的影子了. 只是做什么都无法进行 migrate 操作了
from aerich.
貌似是一个bug,我看一下
from aerich.
已修复
from aerich.
好的, 我再尝试一下
from aerich.
完美解决, 大佬牛逼!
from aerich.
- facing same issue with version 0.3.1
aerich/migrate.py", line 348, in diff_model if old_field.db_constraint and not new_field.db_constraint: AttributeError: 'ForeignKeyFieldInstance' object has no attribute 'db_constraint'
from aerich.
Sorry my tortoise version was 0.16.13, it required to be 0.16.15
it's working fine now
from aerich.
Related Issues (20)
- varchar max_length change not detected HOT 2
- Improved feedback for "migrate" when models and schema are in sync
- aerich inspectdb makes syntax error
- Pydantic validation error when inspecting DB HOT 4
- AttributeError: 'method_descriptor' object has no attribute '__module__'. Did you mean: '__reduce__'? HOT 1
- stuck on init HOT 13
- FK column rename error
- FK column unique not working
- migrate() got an unexpected keyword argument 'empty' HOT 2
- Model with multiple FKs to same table throws error or finds changes that aren't there
- Insert into a glossary table HOT 1
- Support altering columns in SQLite migrations by RENAME-ADD-UPDATE-DROP HOT 1
- Setting null = false on m2m fields causes migration to fail
- Multiple database HOT 2
- Migrate from `CharField(...,unique=True)` to `CharField(...,unique=False)` raises tortoise.exceptions.OperationalError HOT 1
- `make test_postgres` failed with `tortoise-orm>=0.21`
- UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 84: character maps to <undefined>
- Support 3.12.4
- Error reported when add and modify many to many relationships
- RuntimeWarning: Module "x.x.x" has no models HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aerich.