N
N
nikita15422021-11-10 19:55:20
SQLite
nikita1542, 2021-11-10 19:55:20

python flask sqlite error?

My app code

from flask import Flask, render_template, url_for
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime

app= Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URL'] = 'sqlite://blog.db'
db = SQLAlchemy(app)


class Article(db.Model):
    id = db.Column(db.Integer, nullable=True)
    id = db.Column(db.String(100), nullable=False)
    id = db.Column(db.String(300), nullable=False)
    id = db.Column(db.Text, nullable=False)
    id = db.Column(db.DateTime, default=datetime.utcnow)

    def __repr__(self):
        return '<Article %r>' % self.id


my error when calling from app import db

C:\Users\никита\Desktop\app>python Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from app import db C:\Users\никита\AppData\Local\Programs\Python\Python36\lib\site-packages\flask_sqlalchemy\__init__.py:852: UserWarning: Neither SQLALCHEMY_DATABASE_URI nor SQLALCHEMY_BINDS is set. Defaulting SQLALCHEMY_DATABASE_URI to "sqlite:///:memory:". 'Neither SQLALCHEMY_DATABASE_URI nor SQLALCHEMY_BINDS is set. ' C:\Users\никита\AppData\Local\Programs\Python\Python36\lib\site-packages\flask_sqlalchemy\__init__.py:873: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True or False to suppress this warning. 'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and ' Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\никита\Desktop\app\app.py", line 10, in <module> class Article(db.Model): File "C:\Users\никита\AppData\Local\Programs\Python\Python36\lib\site-packages\flask_sqlalchemy\model.py", line 67, in __init__ super(NameMetaMixin, cls).__init__(name, bases, d) File "C:\Users\никита\AppData\Local\Programs\Python\Python36\lib\site-packages\flask_sqlalchemy\model.py", line 121, in __init__ super(BindMetaMixin, cls).__init__(name, bases, d) File "C:\Users\никита\AppData\Local\Programs\Python\Python36\lib\site-packages\sqlalchemy\orm\decl_api.py", line 72, in __init__ _as_declarative(reg, cls, dict_) File "C:\Users\никита\AppData\Local\Programs\Python\Python36\lib\site-packages\sqlalchemy\orm\decl_base.py", line 126, in _as_declarative return _MapperConfig.setup_mapping(registry, cls, dict_, None, {}) File "C:\Users\никита\AppData\Local\Programs\Python\Python36\lib\site-packages\sqlalchemy\orm\decl_base.py", line 177, in setup_mapping return cfg_cls(registry, cls_, dict_, table, mapper_kw) File "C:\Users\никита\AppData\Local\Programs\Python\Python36\lib\site-packages\sqlalchemy\orm\decl_base.py", line 326, in __init__ self._early_mapping(mapper_kw) File "C:\Users\никита\AppData\Local\Programs\Python\Python36\lib\site-packages\sqlalchemy\orm\decl_base.py", line 209, in _early_mapping self.map(mapper_kw) File "C:\Users\никита\AppData\Local\Programs\Python\Python36\lib\site-packages\sqlalchemy\orm\decl_base.py", line 1004, in map mapper_cls(self.cls, self.local_table, **self.mapper_args), File "<string>", line 2, in __init__ File "C:\Users\никита\AppData\Local\Programs\Python\Python36\lib\site-packages\sqlalchemy\util\deprecations.py", line 298, in warned return fn(*args, **kwargs) File "C:\Users\никита\AppData\Local\Programs\Python\Python36\lib\site-packages\sqlalchemy\orm\mapper.py", line 685, in __init__ self._configure_pks() File "C:\Users\никита\AppData\Local\Programs\Python\Python36\lib\site-packages\sqlalchemy\orm\mapper.py", line 1373, in _configure_pks % (self, self.persist_selectable.description) sqlalchemy.exc.ArgumentError: Mapper mapped class Article->article could not assemble any primary key columns for mapped table 'article'

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question