我在使用 python 3.3 在 mysql 中创建表时遇到问题。我正在使用 Pymysql-0.15 和 SQLAlchemy。
目前我正在 Pythonwin 中运行此代码并具有以下输出。
from sqlalchemy imort *
from sqlalchemy import *
import pymysql
engine = create_engine("mysql+pymysql://admin:admin@127.0.0.1/dbeerste")
engine = create_engine("mysql+pymysql://admin:admin@127.0.0.1/dbeerste")
metadata = MetaData(bind=engine)
users_table = Table('users', metadata, Column('id', Integer, primary_key=True), Column('name', String(40)), Column('age', Integer), Column('password', String),)
metadata.create_all(engine)
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\schema.py", line 2740, in create_all
tables=tables)
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\engine\base.py", line 1489, in _run_visitor
conn._run_visitor(visitorcallable, element, **kwargs)
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\engine\base.py", line 1132, in _run_visitor
**kwargs).traverse_single(element)
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\sql\visitors.py", line 109, in traverse_single
return meth(obj, **kw)
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\engine\ddl.py", line 56, in visit_metadata
collection = [t for t in sql_util.sort_tables(tables)
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\engine\ddl.py", line 57, in <listcomp>
if self._can_create_table(t)]
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\engine\ddl.py", line 35, in _can_create_table
table.name, schema=table.schema)
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\dialects\mysql\base.py", line 2039, in has_table
rs = connection.execute(st)
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\engine\base.py", line 664, in execute
params)
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\engine\base.py", line 808, in _execute_text
statement, parameters
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\engine\base.py", line 878, in _execute_context
context)
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\engine\base.py", line 1036, in _handle_dbapi_exception
from e
sqlalchemy.exc.ProgrammingError: (ProgrammingError) (1146, "#42S02Table 'dbeerste.users' doesn't exist") b'DESCRIBE `users`' ()
有人可以帮我解决这个问题吗?