AttributeError 'SQLAlchemy' object has no attribute 'create'


Sachin Mena

I am trying to create a database using sqlalchemy and I am getting db.create.all()this error:

File "<stdin>", line 1, in <module>
AttributeError: 'SQLAlchemy' object has no attribute 'create'

my code:

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

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

class BlogPost(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False )
    content = db.Column(db.Text, nullable=False)
    author = db.Column(db.String(20), nullable=False , default='N/A')
    date_posted = db.Column(db.DateTime, nullable=False ,default= datetime.utcnow())
    
    def __repr__(self):
        return 'BlogPost' + str(self.id)
Mayank porwal

I think it should be db.create_all()replaced db.create.all().

Related


AttributeError 'SQLAlchemy' object has no attribute 'create'

Sachin Mena I am trying to create a database using sqlalchemy and I am getting db.create.all()this error: File "<stdin>", line 1, in <module> AttributeError: 'SQLAlchemy' object has no attribute 'create' my code: from flask import Flask, render_template from

AttributeError 'SQLAlchemy' object has no attribute 'create'

Sachin Mena I am trying to create a database using sqlalchemy and I am getting db.create.all()this error: File "<stdin>", line 1, in <module> AttributeError: 'SQLAlchemy' object has no attribute 'create' my code: from flask import Flask, render_template from

AttributeError 'SQLAlchemy' object has no attribute 'create'

Sachin Mena I am trying to create a database using sqlalchemy and I am getting db.create.all()this error: File "<stdin>", line 1, in <module> AttributeError: 'SQLAlchemy' object has no attribute 'create' my code: from flask import Flask, render_template from

AttributeError 'SQLAlchemy' object has no attribute 'create'

Sachin Mena I am trying to create a database using sqlalchemy and I am getting db.create.all()this error: File "<stdin>", line 1, in <module> AttributeError: 'SQLAlchemy' object has no attribute 'create' my code: from flask import Flask, render_template from

AttributeError - object has no attribute 'create'

Andrew O I'm trying to save a passthrough model with the following properties via Django-rest-framework When sending a POST (I'm trying to create a new instance), I get the following error: AttributeError for /api/organisation/provider/ 'EnabledExternalProvide

SQLAlchemy "AttributeError: 'str' object has no attribute 'c'"

WiGeeky: I have two tables named usersand permissionsI want to create a relationship between them using the specified table userPermissions. Here's what my code looks like: 类User(Base): __tablename__ ='用户' id =列(Integer,primary_key = True) first_

AttributeError: 'SQLAlchemy' object has no attribute 'FieldType'

OK Python, flask and sqlalchemy newbies here. I am writing a small application to collect data (from an excel file) from different groups (departments). Each department will have associated tables and associated fields. Fields will have predefined types (numbe

SQLAlchemy: AttributeError: 'table' object has no attribute 'id'

Yevgeny I am building a database that matches my local product catalog with foreign product catalogs. 'Catalog'SQLAlchemy works fine when I have only unique tables . After adding the tables Competitors, Competitors_catalogall attempts to add records to the two

AttributeError: 'SQLAlchemy' object has no attribute 'datetime'

Wayne I'm following a youtube tutorial on using Flask and when I run this code with python -m flask runit it shows this AttributeError: 'SQLAlchemy' object has no attribute 'datetime'. How can I fix this? from flask import Flask, render_template, url_for from

SQLAlchemy "AttributeError: 'str' object has no attribute 'c'"

WiGeeky: I have two tables named usersand permissionsI want to create a relationship between them using the specified table userPermissions. Here's what my code looks like: 类User(Base): __tablename__ ='用户' id =列(Integer,primary_key = True) first_

AttributeError: 'SQLAlchemy' object has no attribute 'FieldType'

OK Python, flask and sqlalchemy newbies here. I am writing a small application to collect data (from an excel file) from different groups (departments). Each department will have associated tables and associated fields. Fields will have predefined types (numbe

SQLAlchemy: AttributeError: 'table' object has no attribute 'id'

Yevgeny I am building a database that matches my local product catalog with foreign product catalogs. 'Catalog'SQLAlchemy works fine when I have only unique tables . After adding the tables Competitors, Competitors_catalogall attempts to add records to the two

SQLAlchemy: AttributeError: 'table' object has no attribute 'id'

Yevgeny I am building a database that matches my local product catalog with foreign product catalogs. 'Catalog'SQLAlchemy works fine when I have only unique tables . After adding the tables Competitors, Competitors_catalogall attempts to add records to the two

SQLAlchemy: AttributeError: 'table' object has no attribute 'id'

Yevgeny I am building a database that matches my local product catalog with foreign product catalogs. 'Catalog'SQLAlchemy works fine when I have only unique tables . After adding the tables Competitors, Competitors_catalogall attempts to add records to the two

SQLAlchemy: AttributeError: 'table' object has no attribute 'id'

Yevgeny I am building a database that matches my local product catalog with foreign product catalogs. 'Catalog'SQLAlchemy works fine when I have only unique tables . After adding the tables Competitors, Competitors_catalogall attempts to add records to the two

Falcon, AttributeError: 'API' object has no attribute 'create'

username I'm trying to test my falcon route but the test keeps failing and it looks like I'm doing everything right. mineapp.py import falcon from resources.static import StaticResource api = falcon.API() api.add_route('/', StaticResource()) and my test dir

Falcon, AttributeError: 'API' object has no attribute 'create'

username I'm trying to test my falcon route but the test keeps failing and it looks like I'm doing everything right. mineapp.py import falcon from resources.static import StaticResource api = falcon.API() api.add_route('/', StaticResource()) and my test dir

Falcon, AttributeError: 'API' object has no attribute 'create'

username I'm trying to test my falcon route but the test keeps failing and it looks like I'm doing everything right. mineapp.py import falcon from resources.static import StaticResource api = falcon.API() api.add_route('/', StaticResource()) and my test dir

Falcon, AttributeError: 'API' object has no attribute 'create'

username I'm trying to test my falcon route but the test keeps failing and it looks like I'm doing everything right. mineapp.py import falcon from resources.static import StaticResource api = falcon.API() api.add_route('/', StaticResource()) and my test dir

Falcon, AttributeError: 'API' object has no attribute 'create'

username I'm trying to test my falcon route but the test keeps failing and it looks like I'm doing everything right. mineapp.py import falcon from resources.static import StaticResource api = falcon.API() api.add_route('/', StaticResource()) and my test dir

Falcon, AttributeError: 'API' object has no attribute 'create'

username I'm trying to test my falcon route but the test keeps failing and it looks like I'm doing everything right. mineapp.py import falcon from resources.static import StaticResource api = falcon.API() api.add_route('/', StaticResource()) and my test dir