I'm trying to connect my application with MySQL Database engine on Cpanel hosting platform but every time I tried to run makemigrations there's always this long error:
Traceback (most recent call last):
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/db/backends/base/base.py", line 244, in ensure_connection
self.connect()
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/db/backends/base/base.py", line 225, in connect
self.connection = self.get_new_connection(conn_params)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/django/base.py", line 366, in get_new_connection
cnx = mysql.connector.connect(**conn_params)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/pooling.py", line 286, in connect
return CMySQLConnection(*args, **kwargs)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/connection_cext.py", line 101, in __init__
self.connect(**kwargs)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/abstracts.py", line 1099, in connect
self._post_connection()
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/abstracts.py", line 1071, in _post_connection
self.set_charset_collation(self._charset_id)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/abstracts.py", line 1016, in set_charset_collation
) = CharacterSet.get_charset_info(charset)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/constants.py", line 775, in get_charset_info
info = cls.get_default_collation(charset)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/constants.py", line 746, in get_default_collation
raise ProgrammingError(f"Character set '{charset}' unsupported")
mysql.connector.errors.ProgrammingError: Character set '255' unsupported
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home2/cmsmcsc1/cmsmcs/manage.py", line 22, in <module>
main()
File "/home2/cmsmcsc1/cmsmcs/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/core/management/__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/core/management/base.py", line 414, in run_from_argv
self.execute(*args, **cmd_options)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/core/management/base.py", line 460, in execute
output = self.handle(*args, **options)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/core/management/base.py", line 98, in wrapped
res = handle_func(*args, **kwargs)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/core/management/commands/makemigrations.py", line 119, in handle
loader.check_consistent_history(connection)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/db/migrations/loader.py", line 313, in check_consistent_history
applied = recorder.applied_migrations()
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/db/migrations/recorder.py", line 81, in applied_migrations
if self.has_table():
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/db/migrations/recorder.py", line 57, in has_table
with self.connection.cursor() as cursor:
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/db/backends/base/base.py", line 284, in cursor
return self._cursor()
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/db/backends/base/base.py", line 260, in _cursor
self.ensure_connection()
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/db/backends/base/base.py", line 244, in ensure_connection
self.connect()
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/db/utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/db/backends/base/base.py", line 244, in ensure_connection
self.connect()
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/db/backends/base/base.py", line 225, in connect
self.connection = self.get_new_connection(conn_params)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/django/base.py", line 366, in get_new_connection
cnx = mysql.connector.connect(**conn_params)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/pooling.py", line 286, in connect
return CMySQLConnection(*args, **kwargs)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/connection_cext.py", line 101, in __init__
self.connect(**kwargs)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/abstracts.py", line 1099, in connect
self._post_connection()
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/abstracts.py", line 1071, in _post_connection
self.set_charset_collation(self._charset_id)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/abstracts.py", line 1016, in set_charset_collation
) = CharacterSet.get_charset_info(charset)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/constants.py", line 775, in get_charset_info
info = cls.get_default_collation(charset)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/constants.py", line 746, in get_default_collation
raise ProgrammingError(f"Character set '{charset}' unsupported")
django.db.utils.ProgrammingError: (-1, "Character set '255' unsupported", None)
Does anyone knows what to do, please?
try it it will definitely helps you
run the command in your Cpanel Hosting Terminal
pip3 install mysql-connector-python==8.0.29
Related
First I have migrate and makemigrations and then I have dump data with this command:
python manage.py dumpdata --exclude auth.permission --exclude contenttypes > dvvv.json
I have tried to flush the database but when I execute python manage.py loaddata dvvv.json the following error occurs:
pymysql.err.ProgrammingError: (1146, "Table 'webcnytc_prilert_tool.Prilert_confirmationemail' doesn't exist")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/root/Django/my_env/lib/python3.7/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/root/Django/my_env/lib/python3.7/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/root/Django/my_env/lib/python3.7/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/root/Django/my_env/lib/python3.7/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/root/Django/my_env/lib/python3.7/site-packages/django/core/management/commands/loaddata.py", line 78, in handle
self.loaddata(fixture_labels)
File "/root/Django/my_env/lib/python3.7/site-packages/django/core/management/commands/loaddata.py", line 123, in loaddata
self.load_label(fixture_label)
File "/root/Django/my_env/lib/python3.7/site-packages/django/core/management/commands/loaddata.py", line 190, in load_label
obj.save(using=self.using)
File "/root/Django/my_env/lib/python3.7/site-packages/django/core/serializers/base.py", line 223, in save
models.Model.save_base(self.object, using=using, raw=True, **kwargs)
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/models/base.py", line 778, in save_base
force_update, using, update_fields,
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/models/base.py", line 859, in _save_table
forced_update)
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/models/base.py", line 912, in _do_update
return filtered._update(values) > 0
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/models/query.py", line 802, in _update
return query.get_compiler(self.db).execute_sql(CURSOR)
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1559, in execute_sql
cursor = super().execute_sql(result_type)
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1175, in execute_sql
cursor.execute(sql, params)
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 73, in execute
return self.cursor.execute(query, args)
File "/root/Django/my_env/lib/python3.7/site-packages/pymysql/cursors.py", line 148, in execute
result = self._query(query)
File "/root/Django/my_env/lib/python3.7/site-packages/pymysql/cursors.py", line 310, in _query
conn.query(q)
File "/root/Django/my_env/lib/python3.7/site-packages/pymysql/connections.py", line 548, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/root/Django/my_env/lib/python3.7/site-packages/pymysql/connections.py", line 775, in _read_query_result
result.read()
File "/root/Django/my_env/lib/python3.7/site-packages/pymysql/connections.py", line 1156, in read
first_packet = self.connection._read_packet()
File "/root/Django/my_env/lib/python3.7/site-packages/pymysql/connections.py", line 725, in _read_packet
packet.raise_for_error()
File "/root/Django/my_env/lib/python3.7/site-packages/pymysql/protocol.py", line 221, in raise_for_error
err.raise_mysql_exception(self._data)
File "/root/Django/my_env/lib/python3.7/site-packages/pymysql/err.py", line 143, in raise_mysql_exception
raise errorclass(errno, errval)
django.db.utils.ProgrammingError: Problem installing fixture '/root/Django/dvvv.json': Could not load Prilert.ConfirmationEmail(pk=137): (1146, "Table 'webcnytc_prilert_tool.Prilert_confirmationemail' doesn't exist")
when I initialize airflow using mysql as backend I see below error
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/default.py",
line 453, in connect
return self.dbapi.connect(*cargs, **cparams)
File "/usr/local/lib/python3.7/site-packages/MySQLdb/init.py", line 80,
in Connect
from MySQLdb.connections import Connection
File "/usr/local/lib/python3.7/site-packages/MySQLdb/connections.py", line
36
raise errorclass, errorvalue
^
SyntaxError: invalid syntax
I tried re-installing mysql-python and pymysql still its same
airflow initdb
/usr/local/lib/python3.7/site-packages/airflow/configuration.py:627: DeprecationWarning: You have two airflow.cfg files: /home/airflow/airflow/airflow.cfg and /home/airflow/airflow.cfg. Airflow used to look at ~/airflow/airflow.cfg, even when AIRFLOW_HOME was set to a different value. Airflow will now only read /home/airflow/airflow.cfg, and you should remove the other file
category=DeprecationWarning,
[2019-09-24 12:10:32,310] {settings.py:213} INFO - settings.configure_orm(): Using pool settings. pool_size=5, max_overflow=10, pool_recycle=1800, pid=15403
[2019-09-24 12:10:32,508] {__init__.py:51} INFO - Using executor LocalExecutor
DB: mysql://airdba:***#host/airflow_main
[2019-09-24 12:10:32,820] {db.py:369} INFO - Creating tables
Traceback (most recent call last):
File "/usr/local/bin/airflow", line 32, in <module>
args.func(args)
File "/usr/local/lib/python3.7/site-packages/airflow/bin/cli.py", line 1102, in initdb
db.initdb(settings.RBAC)
File "/usr/local/lib/python3.7/site-packages/airflow/utils/db.py", line 106, in initdb
upgradedb()
File "/usr/local/lib/python3.7/site-packages/airflow/utils/db.py", line 377, in upgradedb
command.upgrade(config, 'heads')
File "/usr/local/lib/python3.7/site-packages/alembic/command.py", line 298, in upgrade
script.run_env()
File "/usr/local/lib/python3.7/site-packages/alembic/script/base.py", line 489, in run_env
util.load_python_file(self.dir, "env.py")
File "/usr/local/lib/python3.7/site-packages/alembic/util/pyfiles.py", line 98, in load_python_file
module = load_module_py(module_id, path)
File "/usr/local/lib/python3.7/site-packages/alembic/util/compat.py", line 173, in load_module_py
spec.loader.exec_module(module)
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/usr/local/lib/python3.7/site-packages/airflow/migrations/env.py", line 92, in <module>
run_migrations_online()
File "/usr/local/lib/python3.7/site-packages/airflow/migrations/env.py", line 78, in run_migrations_online
with connectable.connect() as connection:
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2206, in connect
return self._connection_cls(self, **kwargs)
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 103, in __init__
else engine.raw_connection()
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2306, in raw_connection
self.pool.unique_connection, _connection
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2275, in _wrap_pool_connect
return fn()
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 303, in unique_connection
return _ConnectionFairy._checkout(self)
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 760, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 492, in checkout
rec = pool._do_get()
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/impl.py", line 139, in _do_get
self._dec_overflow()
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__
compat.reraise(exc_type, exc_value, exc_tb)
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 153, in reraise
raise value
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/impl.py", line 136, in _do_get
return self._create_connection()
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 308, in _create_connection
return _ConnectionRecord(self)
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 437, in __init__
self.__connect(first_connect_check=True)
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 639, in __connect
connection = pool._invoke_creator(self)
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/strategies.py", line 114, in connect
return dialect.connect(*cargs, **cparams)
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 453, in connect
return self.dbapi.connect(*cargs, **cparams)
File "/usr/local/lib/python3.7/site-packages/MySQLdb/__init__.py", line 80, in Connect
from MySQLdb.connections import Connection
File "/usr/local/lib/python3.7/site-packages/MySQLdb/connections.py", line 36
raise errorclass, errorvalue
^
SyntaxError: invalid syntax
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 437, in __init__
self.__connect(first_connect_check=True)
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 639, in __connect
connection = pool._invoke_creator(self)
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/strategies.py", line 114, in connect
return dialect.connect(*cargs, **cparams)
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 453, in connect
return self.dbapi.connect(*cargs, **cparams)
File "/usr/local/lib/python3.7/site-packages/MySQLdb/__init__.py", line 80, in Connect
from MySQLdb.connections import Connection
File "/usr/local/lib/python3.7/site-packages/MySQLdb/connections.py", line 36
raise errorclass, errorvalue
^
SyntaxError: invalid syntax
removed mysql-python module and forced airflow to use pymysql.
changed connection string in airflow.cfg
sql_alchemy_conn = mysql+pymysql://user:password#server/dbname
Python Version - 3.7.2
Django Version - 2.1.5
I am getting the error below after command >python manage.py migrate
please find the attached error message.
(py1) C:\Users\tejra\Documents\DjangoProject\Dproject>python manage.py migrate
Traceback (most recent call last):
File "C:\Users\tejra\Envs\py1\lib\site-packages\django\db\backends\base\base.py", line 216, in ensure_connection
self.connect()
File "C:\Users\tejra\Envs\py1\lib\site-packages\django\db\backends\base\base.py", line 194, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\tejra\Envs\py1\lib\site-packages\django\db\backends\mysql\base.py", line 227, in get_new_connection
return Database.connect(**conn_params)
File "C:\Users\tejra\Envs\py1\lib\site-packages\MySQLdb\__init__.py", line 85, in Connect
return Connection(*args, **kwargs)
File "C:\Users\tejra\Envs\py1\lib\site-packages\MySQLdb\connections.py", line 204, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1045, "Access denied for user 'root'#'localhost' (using password: YES)")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\tejra\Envs\py1\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\tejra\Envs\py1\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\tejra\Envs\py1\lib\site-packages\django\core\management\base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\tejra\Envs\py1\lib\site-packages\django\core\management\base.py", line 350, in execute
self.check()
File "C:\Users\tejra\Envs\py1\lib\site-packages\django\core\management\base.py", line 379, in check
include_deployment_checks=include_deployment_checks,
File "C:\Users\tejra\Envs\py1\lib\site-packages\django\core\management\commands\migrate.py", line 59, in _run_checks
issues = run_checks(tags=[Tags.database])
File "C:\Users\tejra\Envs\py1\lib\site-packages\django\core\checks\registry.py", line 71, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\tejra\Envs\py1\lib\site-packages\django\core\checks\database.py", line 10, in check_database_backends
issues.extend(conn.validation.check(**kwargs))
File "C:\Users\tejra\Envs\py1\lib\site-packages\django\db\backends\mysql\validation.py", line 9, in check
issues.extend(self._check_sql_mode(**kwargs))
File "C:\Users\tejra\Envs\py1\lib\site-packages\django\db\backends\mysql\validation.py", line 13, in _check_sql_mode
with self.connection.cursor() as cursor:
File "C:\Users\tejra\Envs\py1\lib\site-packages\django\db\backends\base\base.py", line 255, in cursor
return self._cursor()
File "C:\Users\tejra\Envs\py1\lib\site-packages\django\db\backends\base\base.py", line 232, in _cursor
self.ensure_connection()
File "C:\Users\tejra\Envs\py1\lib\site-packages\django\db\backends\base\base.py", line 216, in ensure_connection
self.connect()
File "C:\Users\tejra\Envs\py1\lib\site-packages\django\db\utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\tejra\Envs\py1\lib\site-packages\django\db\backends\base\base.py", line 216, in ensure_connection
self.connect()
File "C:\Users\tejra\Envs\py1\lib\site-packages\django\db\backends\base\base.py", line 194, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\tejra\Envs\py1\lib\site-packages\django\db\backends\mysql\base.py", line 227, in get_new_connection
return Database.connect(**conn_params)
File "C:\Users\tejra\Envs\py1\lib\site-packages\MySQLdb\__init__.py", line 85, in Connect
return Connection(*args, **kwargs)
File "C:\Users\tejra\Envs\py1\lib\site-packages\MySQLdb\connections.py", line 204, in __init__
super(Connection, self).__init__(*args, **kwargs2)
django.db.utils.OperationalError: (1045, "Access denied for user 'root'#'localhost' (using password: YES)")
I have trouble when I execute the command python migrate.py migrate.
I'm learning a little about django, and I need synchronize django with a mysql database.
In settings.py file, I put the right database, username and root password, I don't know why is not having access for root.
So here's my error:
(Ambientepython3) leonardo.oliveira#dss-skinner:~/django-tutorials/mysite$ python manage.py migrate
Traceback (most recent call last):
File "/home/leonardo.oliveira/django-tutorials/Ambientepython3/lib/python3.6/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
self.connect()
File "/home/leonardo.oliveira/django-tutorials/Ambientepython3/lib/python3.6/site-packages/django/db/backends/base/base.py", line 194, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/leonardo.oliveira/django-tutorials/Ambientepython3/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 229, in get_new_connection
return Database.connect(**conn_params)
File "/home/leonardo.oliveira/django-tutorials/Ambientepython3/lib/python3.6/site-packages/MySQLdb/__init__.py", line 86, in Connect
return Connection(*args, **kwargs)
File "/home/leonardo.oliveira/django-tutorials/Ambientepython3/lib/python3.6/site-packages/MySQLdb/connections.py", line 204, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1698, "Access denied for user 'root'#'localhost'")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/home/leonardo.oliveira/django-tutorials/Ambientepython3/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/leonardo.oliveira/django-tutorials/Ambientepython3/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/leonardo.oliveira/django-tutorials/Ambientepython3/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/leonardo.oliveira/django-tutorials/Ambientepython3/lib/python3.6/site-packages/django/core/management/base.py", line 350, in execute
self.check()
File "/home/leonardo.oliveira/django-tutorials/Ambientepython3/lib/python3.6/site-packages/django/core/management/base.py", line 379, in check
include_deployment_checks=include_deployment_checks,
File "/home/leonardo.oliveira/django-tutorials/Ambientepython3/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 59, in _run_checks
issues = run_checks(tags=[Tags.database])
File "/home/leonardo.oliveira/django-tutorials/Ambientepython3/lib/python3.6/site-packages/django/core/checks/registry.py", line 71, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/leonardo.oliveira/django-tutorials/Ambientepython3/lib/python3.6/site-packages/django/core/checks/database.py", line 10, in check_database_backends
issues.extend(conn.validation.check(**kwargs))
File "/home/leonardo.oliveira/django-tutorials/Ambientepython3/lib/python3.6/site-packages/django/db/backends/mysql/validation.py", line 9, in check
issues.extend(self._check_sql_mode(**kwargs))
File "/home/leonardo.oliveira/django-tutorials/Ambientepython3/lib/python3.6/site-packages/django/db/backends/mysql/validation.py", line 13, in _check_sql_mode
with self.connection.cursor() as cursor:
File "/home/leonardo.oliveira/django-tutorials/Ambientepython3/lib/python3.6/site-packages/django/db/backends/base/base.py", line 255, in cursor
return self._cursor()
File "/home/leonardo.oliveira/django-tutorials/Ambientepython3/lib/python3.6/site-packages/django/db/backends/base/base.py", line 232, in _cursor
self.ensure_connection()
File "/home/leonardo.oliveira/django-tutorials/Ambientepython3/lib/python3.6/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
self.connect()
File "/home/leonardo.oliveira/django-tutorials/Ambientepython3/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/leonardo.oliveira/django-tutorials/Ambientepython3/lib/python3.6/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
self.connect()
File "/home/leonardo.oliveira/django-tutorials/Ambientepython3/lib/python3.6/site-packages/django/db/backends/base/base.py", line 194, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/leonardo.oliveira/django-tutorials/Ambientepython3/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 229, in get_new_connection
return Database.connect(**conn_params)
File "/home/leonardo.oliveira/django-tutorials/Ambientepython3/lib/python3.6/site-packages/MySQLdb/__init__.py", line 86, in Connect
return Connection(*args, **kwargs)
File "/home/leonardo.oliveira/django-tutorials/Ambientepython3/lib/python3.6/site-packages/MySQLdb/connections.py", line 204, in __init__
super(Connection, self).__init__(*args, **kwargs2)
django.db.utils.OperationalError: (1698, "Access denied for user 'root'#'localhost'")
I've looked here and through Google, and found nothing that seems to describe what I'm seeing. I'm using Django 1.7 with Python 3.4.
ETA: I'm using MySQL 5.6.17
I have the following model (unrelated fields left out):
class Location(models.Model):
location_type = models.CharField(max_length=5,
choices=constants.LocationTypes.LOCATION_CHOICES
)
parent = models.ForeignKey("Location", blank=True, null=True, related_name='location_parent')
room = models.ForeignKey("Location", blank=True, null=True, related_name='location_room')
There are no other instances of "room" anywhere else in models.py except for a comment.
It worked fine until I added the room field (adding the related _name to parent at the same time). Now when I try to run the migration, I get the following:
File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 65, in execute return self.cursor.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\mysql\base.py", line 128, in execute return self.cursor.execute(query, args)
File "C:\Python34\lib\site-packages\pymysql\cursors.py", line 132, in execute result = self._query(query)
File "C:\Python34\lib\site-packages\pymysql\cursors.py", line 271, in _query conn.query(q)
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 726, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 861, in _read_query_result result.read()
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 1064, in read first_packet = self.connection._read_packet()
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 826, in _read_packet packet.check_error()
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 370, in check_error raise_mysql_exception(self._data)
File "C:\Python34\lib\site-packages\pymysql\err.py", line 116, in raise_mysql_exception _check_mysql_exception(errinfo)
File "C:\Python34\lib\site-packages\pymysql\err.py", line 112, in _check_mysql_exception raise InternalError(errno, errorvalue)
pymysql.err.InternalError: (1060, "Duplicate column name 'room_id'")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:/Users/Phoenix/PycharmProjects/gamecon/manage.py", line 10, in <module> execute_from_command_line(sys.argv)
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 385, in execute_from_command_line utility.execute()
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 377, in execute self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 288, in run_from_argv self.execute(*args, **options.__dict__)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 338, in execute output = self.handle(*args, **options)
File "C:\Python34\lib\site-packages\django\core\management\commands\migrate.py", line 160, in handle executor.migrate(targets, plan, fake=options.get("fake", False))
File "C:\Python34\lib\site-packages\django\db\migrations\executor.py", line 63, in migrate self.apply_migration(migration, fake=fake)
File "C:\Python34\lib\site-packages\django\db\migrations\executor.py", line 97, in apply_migration migration.apply(project_state, schema_editor)
File "C:\Python34\lib\site-packages\django\db\migrations\migration.py", line 107, in apply operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
File "C:\Python34\lib\site-packages\django\db\migrations\operations\fields.py", line 37, in database_forwards field,
File "C:\Python34\lib\site-packages\django\db\backends\mysql\schema.py", line 42, in add_field super(DatabaseSchemaEditor, self).add_field(model, field)
File "C:\Python34\lib\site-packages\django\db\backends\schema.py", line 390, in add_field self.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\schema.py", line 99, in execute cursor.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 81, in execute return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 65, in execute return self.cursor.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\utils.py", line 94, in __exit__ six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Python34\lib\site-packages\django\utils\six.py", line 549, in reraise raise value.with_traceback(tb)
File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 65, in execute return self.cursor.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\mysql\base.py", line 128, in execute return self.cursor.execute(query, args)
File "C:\Python34\lib\site-packages\pymysql\cursors.py", line 132, in execute result = self._query(query)
File "C:\Python34\lib\site-packages\pymysql\cursors.py", line 271, in _query conn.query(q)
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 726, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 861, in _read_query_result result.read()
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 1064, in read first_packet = self.connection._read_packet()
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 826, in _read_packet packet.check_error()
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 370, in check_error raise_mysql_exception(self._data)
File "C:\Python34\lib\site-packages\pymysql\err.py", line 116, in raise_mysql_exception _check_mysql_exception(errinfo)
File "C:\Python34\lib\site-packages\pymysql\err.py", line 112, in _check_mysql_exception raise InternalError(errno, errorvalue)
django.db.utils.InternalError: (1060, "Duplicate column name 'room_id'")
Can someone please tell me what I'm missing here?
Made answer from comment
if you are doing ForeignKey on the model itself you should do it like this
models.ForeignKey("self", blank=True, null=True, related_name='location_parent')