Skip to content
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

Transferring Data/schema to the DB fails during migration #411

Open
LexPM1 opened this issue Jan 23, 2025 · 3 comments
Open

Transferring Data/schema to the DB fails during migration #411

LexPM1 opened this issue Jan 23, 2025 · 3 comments

Comments

@LexPM1
Copy link

LexPM1 commented Jan 23, 2025

Whenever a change is made to PostgreSQL database schema, and I am trying to migrate the data to the DB, this process always throws errors and is mostly unsuccessful. Also, if the tables are deleted and one wants to carry out a fresh migration

I see a number of devs have raised an issue concerning migration already, would be so kind to let us know when this issue would be resolved. Thanks

@LexPM1 LexPM1 changed the title Database Migration Transferring Data/schema to the DB fails during migration Jan 23, 2025
@waketzheng
Copy link
Contributor

Cloud you add more details for how to reproduce the errors?

@charleeBlaqTech
Copy link

Cloud you add more details for how to reproduce the errors?

pls check this out, after initialization if i try running the following command ;

poetry run aerich init-db
OR
poetry run aerich upgrade

the poetry run aerich migrate generates the file successfully. example 0_20250129141703_init.py

Traceback (most recent call last):
File "asyncpg\protocol\prepared_stmt.pyx", line 175, in asyncpg.protocol.protocol.PreparedStatementState._encode_bind_msg
File "asyncpg\protocol\codecs/base.pyx", line 227, in asyncpg.protocol.protocol.Codec.encode
File "asyncpg\protocol\codecs/base.pyx", line 129, in asyncpg.protocol.protocol.Codec.encode_scalar
File "asyncpg\pgproto\./codecs/bytea.pyx", line 19, in asyncpg.pgproto.pgproto.bytea_encode
TypeError: a bytes-like object is required, not 'str'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\CharlesDaudu\AppData\Local\pypoetry\Cache\virtualenvs\src-ICuY37V0-py3.11\Lib\site-packages\tortoise\backends\asyncpg\client.py", line 87, in _translate_exceptions
return await func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\CharlesDaudu\AppData\Local\pypoetry\Cache\virtualenvs\src-ICuY37V0-py3.11\Lib\site-packages\tortoise\backends\asyncpg\client.py", line 110, in execute_insert
return await connection.fetchrow(query, *values)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\CharlesDaudu\AppData\Local\pypoetry\Cache\virtualenvs\src-ICuY37V0-py3.11\Lib\site-packages\asyncpg\connection.py", line 748, in fetchrow
data = await self._execute(
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\CharlesDaudu\AppData\Local\pypoetry\Cache\virtualenvs\src-ICuY37V0-py3.11\Lib\site-packages\asyncpg\connection.py", line 1864, in _execute
result, _ = await self.__execute(
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\CharlesDaudu\AppData\Local\pypoetry\Cache\virtualenvs\src-ICuY37V0-py3.11\Lib\site-packages\asyncpg\connection.py", line 1961, in __execute
result, stmt = await self._do_execute(
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\CharlesDaudu\AppData\Local\pypoetry\Cache\virtualenvs\src-ICuY37V0-py3.11\Lib\site-packages\asyncpg\connection.py", line 2025, in _do_execute
result = await executor(stmt, None)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "asyncpg\protocol\protocol.pyx", line 185, in bind_execute
File "asyncpg\protocol\prepared_stmt.pyx", line 204, in asyncpg.protocol.protocol.PreparedStatementState._encode_bind_msg
asyncpg.exceptions.DataError: invalid input for query argument $1: '0_20250129141703_init.py' (a bytes-like object is required, not 'str')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in run_code
File "C:\Users\CharlesDaudu\AppData\Local\pypoetry\Cache\virtualenvs\src-ICuY37V0-py3.11\Scripts\aerich.exe_main
.py", line 7, in
File "C:\Users\CharlesDaudu\AppData\Local\pypoetry\Cache\virtualenvs\src-ICuY37V0-py3.11\Lib\site-packages\aerich\cli.py", line 257, in main

File "C:\Users\CharlesDaudu\AppData\Local\pypoetry\Cache\virtualenvs\src-ICuY37V0-py3.11\Lib\site-packages\tortoise\backends\asyncpg\client.py", line 89, in _translate_exceptions
raise OperationalError(exc)
tortoise.exceptions.OperationalError: invalid input for query argument $1: '0_20250129141703_init.py' (a bytes-like object is required, no raise OperationalError(exc)
tortoise.exceptions.OperationalError: invalid input for query argument $1: '0_20250129141703_init.py' (a bytes-like object is required, notortoise.exceptions.OperationalError: invalid input for query argument $1: '0_20250129141703_init.py' (a bytes-like object is required, not 'str')

@waketzheng
Copy link
Contributor

@charleeBlaqTech What's your aerich version and tortoise-orm version? And what's the output of cat migrations/*/0_*.py?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants