Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

DatabaseError - sqlalchemy.exc.DatabaseError: (mysql.connector.errors.DatabaseError) 1273 (HY000): Unknown collation: 'utf8mb4_0900_ai_ci' (Background on this error at: https://sqlalche.me/e/20/4xp6)

sqlalchemy.exc.DatabaseError: (mysql.connector.errors.DatabaseError) 1273 (HY000): Unknown collation: 'utf8mb4_0900_ai_ci' (Background on this error at: https://sqlalche.me/e/20/4xp6)

Traceback (most recent call last) File "C:\Users\jumpe\PycharmProjects\PythonFlaskProject\venv\Lib\site-packages\sqlalchemy\engine\base.py", line 145, in init self._dbapi_connection = engine.raw_connection() ^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\jumpe\PycharmProjects\PythonFlaskProject\venv\Lib\site-packages\sqlalchemy\engine\base.py", line 3288, in raw_connection return self.pool.connect() ^^^^^^^^^^^^^^^^^^^ File "C:\Users\jumpe\PycharmProjects\PythonFlaskProject\venv\Lib\site-packages\sqlalchemy\pool\base.py", line 452, in connect return _ConnectionFairy._checkout(self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\jumpe\PycharmProjects\PythonFlaskProject\venv\Lib\site-packages\sqlalchemy\pool\base.py", line 1267, in _checkout fairy = _ConnectionRecord.checkout(pool) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\jumpe\PycharmProjects\PythonFlaskProject\venv\Lib\site-packages\sqlalchemy\pool\base.py", line 716, in checkout rec = pool._do_get() ^^^^^^^^^^^^^^ File "C:\Users\jumpe\PycharmProjects\PythonFlaskProject\venv\Lib\site-packages\sqlalchemy\pool\impl.py", line 169, in _do_get with util.safe_reraise(): ^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\jumpe\PycharmProjects\PythonFlaskProject\venv\Lib\site-packages\sqlalchemy\util\langhelpers.py", line 147, in exit raise exc_value.with_traceback(exc_tb) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\jumpe\PycharmProjects\PythonFlaskProject\venv\Lib\site-packages\sqlalchemy\pool\impl.py", line 167, in _do_get return self._create_connection() ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\jumpe\PycharmProjects\PythonFlaskProject\venv\Lib\site-packages\sqlalchemy\pool\base.py", line 393, in _create_connection return _ConnectionRecord(self) ^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\jumpe\PycharmProjects\PythonFlaskProject\venv\Lib\site-packages\sqlalchemy\pool\base.py", line 678, in init self.__connect() ^^^^^^^^^^^^^^^^ File "C:\Users\jumpe\PycharmProjects\PythonFlaskProject\venv\Lib\site-packages\sqlalchemy\pool\base.py", line 902, in __connect with util.safe_reraise(): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\jumpe\PycharmProjects\PythonFlaskProject\venv\Lib\site-packages\sqlalchemy\util\langhelpers.py", line 147, in exit raise exc_value.with_traceback(exc_tb) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\jumpe\PycharmProjects\PythonFlaskProject\venv\Lib\site-packages\sqlalchemy\pool\base.py", line 898, in __connect self.dbapi_connection = connection = pool.invoke_creator(self) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\jumpe\PycharmProjects\PythonFlaskProject\venv\Lib\site-packages\sqlalchemy\engine\create.py", line 637, in connect return dialect.connect(*cargs, **cparams) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\jumpe\PycharmProjects\PythonFlaskProject\venv\Lib\site-packages\sqlalchemy\engine\default.py", line 615, in connect return self.loaded_dbapi.connect(*cargs, **cparams) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\jumpe\PycharmProjects\PythonFlaskProject\venv\Lib\site-packages\mysql\connector_init.py", line 273, in connect return MySQLConnection(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\jumpe\PycharmProjects\PythonFlaskProject\venv\Lib\site-packages\mysql\connector\connection.py", line 115, in init self.connect(**kwargs) ^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\jumpe\PycharmProjects\PythonFlaskProject\venv\Lib\site-packages\mysql\connector\abstracts.py", line 1032, in connect self._post_connection() ^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\jumpe\PycharmProjects\PythonFlaskProject\venv\Lib\site-packages\mysql\connector\abstracts.py", line 1004, in _post_connection self.set_charset_collation(self._charset_id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\jumpe\PycharmProjects\PythonFlaskProject\venv\Lib\site-packages\mysql\connector\abstracts.py", line 962, in set_charset_collation self._execute_query("SET NAMES '{0}' COLLATE '{1}'".format( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\jumpe\PycharmProjects\PythonFlaskProject\venv\Lib\site-packages\mysql\connector\connection.py", line 1339, in _execute_query self.cmd_query(query) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\jumpe\PycharmProjects\PythonFlaskProject\venv\Lib\site-packages\mysql\connector\connection.py", line 920, in cmd_query result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Etc...

1 resposta
solução!

Tentei isso e até melhorou o erro quando eu instalei umas versões mais novas mas não resolveu, aí percebi uma coisa que professor não ensinou pois não fez a instalação do MySQL, percebi que: mysql-connector-python==8.0.28 e o MySQL 8.0.28 ou seja, eles tinham as mesmas versões aí pensei será coincidência, será se eu instalar: mysql-connector-python==8.0.34 eu terei que instalar MySQL Installer 8.0.34

Então eu baixei as mesmas versões e funcionou, pena que eu perdi um tempo absurdo tentando descobrir isso se o professor tivesse dado essa aula de instalação e falado os detalhes.

https://dev.mysql.com/downloads/installer/ Instalar e desinstalar vários pacotes com um só comando: 1º - instale freeze pip freeze

2º Instale o arquivo com lista de pacotes ou pode criar ele manualmente pip freeze > requirements.txt

3º - Instale vários pacotes um por um ou pegue uma lista de pacotes copie e cole no arquivo de pacotes Flask==2.2.2 mysql-connector-python==8.0.28 Flask-SQLAlchemy==3.0.3 Flask-WTF==1.0.0 Flask-Bcrypt==1.0.1

obs: Cada vez que instalar um pacou use o comando abaixo pip freeze > requirements.txt

4º - desinstalar todos os pacotes de uma vez só pip uninstall -r requirements.txt

obs: Depois de desinstalar todos os pacotes Abra o arquivo de requirements.txt, exclua seu conteúdo, adicione as dependências a seguir e salve o arquivo:

Flask==2.2.2 mysql-connector-python==8.0.28 Flask-SQLAlchemy==3.0.3 Flask-WTF==1.0.0 Flask-Bcrypt==1.0.1

Instale as bibliotecas listadas no arquivo de requirements.txt, com o comando a seguir:

pip install -r .\requirements.txt