mysql 1050エラー:テーブルは既に存在します
今日練習して、ライブラリを作成して、表を修正する時、ずっと
結局table_名前は小文字でなければ変更できません.テーブルを作成するときにテーブル名を小文字に変更しますが、sqlalchemyは大文字と小文字を区別するので、テーブルが新しく作成されたと考えられます.
の間違いを報告しますpymysql.err.InternalError: (1050, "Table 'usermodel' already exists")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 20, in
manager.run()
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\flask_script\__init__.py", line 417, in run
result = self.handle(argv[0], argv[1:])
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\flask_script\__init__.py", line 386, in handle
res = handle(*args, **config)
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\flask_script\commands.py", line 216, in __call__
return self.run(*args, **kwargs)
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\flask_migrate\__init__.py", line 96, in wrapped
f(*args, **kwargs)
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\flask_migrate\__init__.py", line 271, in upgrade
command.upgrade(config, revision, sql=sql, tag=tag)
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\alembic\command.py", line 298, in upgrade
script.run_env()
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\alembic\script\base.py", line 489, in run_env
util.load_python_file(self.dir, "env.py")
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\alembic\util\pyfiles.py", line 98, in load_python_file
module = load_module_py(module_id, path)
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\alembic\util\compat.py", line 184, in load_module_py
spec.loader.exec_module(module)
File "", line 728, in exec_module
File "", line 219, in _call_with_frames_removed
File "migrations\env.py", line 96, in
run_migrations_online()
File "migrations\env.py", line 90, in run_migrations_online
context.run_migrations()
File "", line 8, in run_migrations
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\alembic\runtime\environment.py", line 846, in run_migrations
self.get_context().run_migrations(**kw)
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\alembic\runtime\migration.py", line 520, in run_migrations
step.migration_fn(**kw)
File "D:\python_code\Day18\FlaskModel\migrations\versions\28db8668d325_.py", line 27, in upgrade
sa.PrimaryKeyConstraint('id')
File "", line 8, in create_table
File "", line 3, in create_table
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\alembic\operations\ops.py", line 1252, in create_table
return operations.invoke(op)
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\alembic\operations\base.py", line 374, in invoke
return fn(self, operation)
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\alembic\operations\toimpl.py", line 101, in create_table
operations.impl.create_table(table)
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\alembic\ddl\impl.py", line 258, in create_table
self._exec(schema.CreateTable(table))
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\alembic\ddl\impl.py", line 140, in _exec
return conn.execute(construct, *multiparams, **params)
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\sqlalchemy\engine\base.py", line 1020, in execute
return meth(self, multiparams, params)
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\sqlalchemy\sql\ddl.py", line 72, in _execute_on_connection
return connection._execute_ddl(self, multiparams, params)
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\sqlalchemy\engine\base.py", line 1082, in _execute_ddl
compiled,
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\sqlalchemy\engine\base.py", line 1324, in _execute_context
e, statement, parameters, cursor, context
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\sqlalchemy\engine\base.py", line 1518, in _handle_dbapi_exception
sqlalchemy_exception, with_traceback=exc_info[2], from_=e
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\sqlalchemy\util\compat.py", line 178, in raise_
raise exception
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\sqlalchemy\engine\base.py", line 1284, in _execute_context
cursor, statement, parameters, context
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\sqlalchemy\engine\default.py", line 590, in do_execute
cursor.execute(statement, parameters)
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\pymysql\cursors.py", line 170, in execute
result = self._query(query)
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\pymysql\cursors.py", line 328, in _query
conn.query(q)
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\pymysql\connections.py", line 517, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\pymysql\connections.py", line 732, in _read_query_result
result.read()
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\pymysql\connections.py", line 1075, in read
first_packet = self.connection._read_packet()
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\pymysql\connections.py", line 684, in _read_packet
packet.check_error()
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\pymysql\protocol.py", line 220, in check_error
err.raise_mysql_exception(self._data)
File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\pymysql\err.py", line 109, in raise_mysql_exception
raise errorclass(errno, errval)
sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1050, "Table 'usermodel' already exists")
[SQL:
CREATE TABLE `UserModel` (
id INTEGER NOT NULL AUTO_INCREMENT,
u_name VARCHAR(16),
u_des VARCHAR(128),
u_phone VARCHAR(128),
u_addr VARCHAR(128),
PRIMARY KEY (id)
)
]
結局table_名前は小文字でなければ変更できません.テーブルを作成するときにテーブル名を小文字に変更しますが、sqlalchemyは大文字と小文字を区別するので、テーブルが新しく作成されたと考えられます.