AttributeError:'NoneType'对象没有属性'db'

时间:2020-03-20 07:44:23

标签: python sqlalchemy

Traceback (most recent call last):
  File "/Users/knutjorgenbjuland/PycharmProjects/assignment_7_1/main.py", line 13, in <module>
    Column('course_id',Integer,ForeignKey('courses.id')))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sqlalchemy/testing/schema.py", line 26, in Table
    if exclusions.against(config._current, "mysql"):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sqlalchemy/testing/exclusions.py", line 452, in against
    config
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sqlalchemy/testing/exclusions.py", line 356, in __call__
    if pred(config):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sqlalchemy/testing/exclusions.py", line 273, in __call__
    engine = config.db
AttributeError: 'NoneType' object has no attribute 'db'

上面和下面的错误是我的代码。

 from sqlalchemy import Table, Column, Integer, String, ForeignKey
 from sqlalchemy import create_engine
 from sqlalchemy.ext.declarative import declarative_base
 from sqlalchemy.orm import relationship, sessionmaker

 # declarative_base() returns the base class used for table descriptions
 from sqlalchemy.testing.schema import Table

 Base = declarative_base()

 students_course_table = Table('student_course',Base.metadata,
                          Column('student_id',Integer,ForeignKey('students.id')),
                          Column('course_id',Integer,ForeignKey('courses.id')))

我已将所有列和表添加到Sqlite数据库。我有什么办法可以纠正此错误?

0 个答案:

没有答案