V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
fmdxx1991
V2EX  ›  Python

关于 sqlalchemy 创建数据库报异常

  •  
  •   fmdxx1991 · Aug 28, 2020 · 2162 views
    This topic created in 2073 days ago, the information mentioned may be changed or developed.
    import requests
    from bs4 import BeautifulSoup
    import re
    import json
    from sqlalchemy import create_engine
    from sqlalchemy.ext.declarative import declarative_base
    from sqlalchemy import Column, Integer, String
    from sqlalchemy.orm import sessionmaker

    engine = create_engine('sqlite:///notice_hyzhdj.db?check_same_thread=False', echo=True)
    Base = declarative_base()

    class Notice(Base):
    __tablename__ = 'notice'
    id = Column(Integer, primary_key=True, autoincrement=True)
    title = Column(String(100))
    src = Column(String(100))
    date = Column(String(32))

    def __init__(self, title, src, date):
    self.title = title
    self.src = src
    self.date = date

    Base.metadata.creat_all(engine)


    运行报错
    AttributeError: 'MetaData' object has no attribute 'creat_all'
    我按照实例敲的,百度也没找到这个错误的原因,求各位大佬指点下
    sqlalchemy 版本是 1.3.19
    3 replies    2020-08-29 21:20:19 +08:00
    j0hnj
        1
    j0hnj  
       Aug 28, 2020
    creat_all => create_all
    fmdxx1991
        2
    fmdxx1991  
    OP
       Aug 28, 2020
    @j0hnj 多谢,解决了!太依赖提示了,没提示就敲错了
    efaun
        3
    efaun  
       Aug 29, 2020
    你需要用 pycharm
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1273 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 16:59 · PVG 00:59 · LAX 09:59 · JFK 12:59
    ♥ Do have faith in what you're doing.