今天做练习,创建库,修改表的时候,一直报表已经存在
的错误
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 <module>manager.run()File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\flask_script\__init__.py", line 417, in runresult = self.handle(argv[0], argv[1:])File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\flask_script\__init__.py", line 386, in handleres = 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 wrappedf(*args, **kwargs)File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\flask_migrate\__init__.py", line 271, in upgradecommand.upgrade(config, revision, sql=sql, tag=tag)File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\alembic\command.py", line 298, in upgradescript.run_env()File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\alembic\script\base.py", line 489, in run_envutil.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_filemodule = 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_pyspec.loader.exec_module(module)File "<frozen importlib._bootstrap_external>", line 728, in exec_moduleFile "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removedFile "migrations\env.py", line 96, in <module>run_migrations_online()File "migrations\env.py", line 90, in run_migrations_onlinecontext.run_migrations()File "<string>", line 8, in run_migrationsFile "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\alembic\runtime\environment.py", line 846, in run_migrationsself.get_context().run_migrations(**kw)File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\alembic\runtime\migration.py", line 520, in run_migrationsstep.migration_fn(**kw)File "D:\python_code\Day18\FlaskModel\migrations\versions\28db8668d325_.py", line 27, in upgradesa.PrimaryKeyConstraint('id')File "<string>", line 8, in create_tableFile "<string>", line 3, in create_tableFile "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\alembic\operations\ops.py", line 1252, in create_tablereturn operations.invoke(op)File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\alembic\operations\base.py", line 374, in invokereturn fn(self, operation)File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\alembic\operations\toimpl.py", line 101, in create_tableoperations.impl.create_table(table)File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\alembic\ddl\impl.py", line 258, in create_tableself._exec(schema.CreateTable(table))File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\alembic\ddl\impl.py", line 140, in _execreturn conn.execute(construct, *multiparams, **params)File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\sqlalchemy\engine\base.py", line 1020, in executereturn meth(self, multiparams, params)File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\sqlalchemy\sql\ddl.py", line 72, in _execute_on_connectionreturn connection._execute_ddl(self, multiparams, params)File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\sqlalchemy\engine\base.py", line 1082, in _execute_ddlcompiled,File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\sqlalchemy\engine\base.py", line 1324, in _execute_contexte, statement, parameters, cursor, contextFile "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\sqlalchemy\engine\base.py", line 1518, in _handle_dbapi_exceptionsqlalchemy_exception, with_traceback=exc_info[2], from_=eFile "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\sqlalchemy\util\compat.py", line 178, in raise_raise exceptionFile "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\sqlalchemy\engine\base.py", line 1284, in _execute_contextcursor, statement, parameters, contextFile "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\sqlalchemy\engine\default.py", line 590, in do_executecursor.execute(statement, parameters)File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\pymysql\cursors.py", line 170, in executeresult = self._query(query)File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\pymysql\cursors.py", line 328, in _queryconn.query(q)File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\pymysql\connections.py", line 517, in queryself._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_resultresult.read()File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\pymysql\connections.py", line 1075, in readfirst_packet = self.connection._read_packet()File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\pymysql\connections.py", line 684, in _read_packetpacket.check_error()File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\pymysql\protocol.py", line 220, in check_errorerr.raise_mysql_exception(self._data)File "D:\Program Files\anaconda3\envs\FlaskModel\lib\site-packages\pymysql\err.py", line 109, in raise_mysql_exceptionraise 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_name必须是小写才能完成修改,因为迁移创建表的时候会将表名转为小写,但是 sqlalchemy是会区分大小写的,所以会认为新建了表