V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2020-08-28 11:21:17 +08:00 · 1517 次点击
    这是一个创建于 1308 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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 条回复    2020-08-29 21:20:19 +08:00
    j0hnj
        1
    j0hnj  
       2020-08-28 11:31:52 +08:00
    creat_all => create_all
    fmdxx1991
        2
    fmdxx1991  
    OP
       2020-08-28 15:39:26 +08:00
    @j0hnj 多谢,解决了!太依赖提示了,没提示就敲错了
    efaun
        3
    efaun  
       2020-08-29 21:20:19 +08:00
    你需要用 pycharm
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2718 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 00:21 · PVG 08:21 · LAX 17:21 · JFK 20:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.