GithubHelp home page GithubHelp logo

Comments (21)

long2ice avatar long2ice commented on August 26, 2024

Yes, this need some update.

from aerich.

long2ice avatar long2ice commented on August 26, 2024

Supported in ce8c0b1 , just try.

from aerich.

miss85246 avatar miss85246 commented on August 26, 2024

@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.

long2ice avatar long2ice commented on August 26, 2024

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.

miss85246 avatar miss85246 commented on August 26, 2024

OK, I'll try it later

from aerich.

miss85246 avatar miss85246 commented on August 26, 2024

image
I upgrade and delete records by your way by it's real nothing to change, fk still there @long2ice

from aerich.

long2ice avatar long2ice commented on August 26, 2024

See change sql what it is, and migrate depends on old_model.py, which should be different from your current models.

from aerich.

miss85246 avatar miss85246 commented on August 26, 2024

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.

miss85246 avatar miss85246 commented on August 26, 2024

Are you Chinese? How about communicate in Chinese, my English is too poor

from aerich.

long2ice avatar long2ice commented on August 26, 2024

升级tortoise

from aerich.

miss85246 avatar miss85246 commented on August 26, 2024

升级 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.

long2ice avatar long2ice commented on August 26, 2024

检查数据库连接

from aerich.

miss85246 avatar miss85246 commented on August 26, 2024

数据库的连接是没有问题的, 我测试了一下删除文件,重新初始化, 没有问题, 连接是成功的, 也成功的进行了表的创建, 随意更改一个字段的参数后,执行 aerich migrate 就出现了这个问题

from aerich.

long2ice avatar long2ice commented on August 26, 2024

那有点奇怪

from aerich.

miss85246 avatar miss85246 commented on August 26, 2024

我现在的问题是, 无论做什么都无法进行 migrate的操作, 但是 外键依旧存在的问题解决了, 我刚才看了一眼数据库, 重新初始化后的表结构里已经没有外键的影子了. 只是做什么都无法进行 migrate 操作了

from aerich.

long2ice avatar long2ice commented on August 26, 2024

貌似是一个bug,我看一下

from aerich.

long2ice avatar long2ice commented on August 26, 2024

已修复

from aerich.

miss85246 avatar miss85246 commented on August 26, 2024

好的, 我再尝试一下

from aerich.

miss85246 avatar miss85246 commented on August 26, 2024

完美解决, 大佬牛逼!

from aerich.

iamku7sh avatar iamku7sh commented on August 26, 2024
  • 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.

iamku7sh avatar iamku7sh commented on August 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.