1

SQLAlchemy script works fine with sqlite3 but when connected to MYSQL database it gives different errors like:

  • AttributeError: '_NoResultMetaData' object has no attribute '_indexes_for_keys'
  • sqlalchemy.exc.NoSuchColumnError: Could not locate column in row for column 'filters.id'
  • KeyError: Column('id', Integer(), table=, primary_key=True, nullable=False)

The functions works fine when running separately but when used with flask they raise above errors.

My DB models:

from sqlalchemy import Column, Integer, String, MetaData, Boolean, DateTime
from sqlalchemy.ext.declarative import declarative_base

import datetime


Base = declarative_base()


class ProfileData(Base):
    __tablename__ = 'profile_data'

    id = Column(Integer, primary_key=True)
    user_id = Column("user_id", Integer)
    user_profile_link = Column(String(100))
    username = Column(String(100))
    name = Column(String(100))
    is_verified = Column(Boolean)
    website = Column(String(100))
    bio = Column(String(1000))
    location = Column(String(100))
    created_at = Column(DateTime)
    followers = Column(Integer)
    following = Column(Integer)
    _datetime = Column(DateTime, default=datetime.datetime.utcnow)

Thanks in advance.

1 Answer 1

1

I would suggest to do this and this how usually do my setup

first init db object from SQLAlchemy

db = SQLAlchemy()

then declare the model using db.model

class ProfileData(db.Model):

    __tablename__ = 'profile_data'

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column("user_id", db.Integer)
    user_profile_link = db.Column(db.String(100))
    username = db.Column(db.String(100))

hope this fix your issue

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. It worked.
always welcome glad it did work :D @HuzaifaFarooq

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.