-1

OS - macOS BigSur 11.2.3
Python - 3.9.2

I am trying to create a database through the Python console using the following commands:

  1. from app import db
  2. db.create_all()
    Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Users/user/PycharmProjects/PhoneBook/venv/lib/python3.9/site-packages/flask_sqlalchemy/__init__.py", line 1039, in create_all
    self._execute_for_all_tables(app, bind, 'create_all')
  File "/Users/user/PycharmProjects/PhoneBook/venv/lib/python3.9/site-packages/flask_sqlalchemy/__init__.py", line 1031, in _execute_for_all_tables
    op(bind=self.get_engine(app, bind), **extra)
  File "/Users/user/PycharmProjects/PhoneBook/venv/lib/python3.9/site-packages/flask_sqlalchemy/__init__.py", line 962, in get_engine
    return connector.get_engine()
  File "/Users/user/PycharmProjects/PhoneBook/venv/lib/python3.9/site-packages/flask_sqlalchemy/__init__.py", line 555, in get_engine
    options = self.get_options(sa_url, echo)
  File "/Users/user/PycharmProjects/PhoneBook/venv/lib/python3.9/site-packages/flask_sqlalchemy/__init__.py", line 570, in get_options
    self._sa.apply_driver_hacks(self._app, sa_url, options)
  File "/Users/user/PycharmProjects/PhoneBook/venv/lib/python3.9/site-packages/flask_sqlalchemy/__init__.py", line 914, in apply_driver_hacks
    sa_url.database = os.path.join(app.root_path, sa_url.database)
AttributeError: can't set attribute

code in my application:

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

app = Flask(__name__)
app.config.from_object(Config)
db = SQLAlchemy(app)

class Abonent(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    firstname = db.Column(db.String(75),nullable=False)
    gender = db.Column(db.String(5),nullable=False)
    lastname = db.Column(db.String(75),nullable=False)
    birthdate = db.Column(db.String(75),nullable=True)
    email = db.Column(db.String(75),nullable=True)
    phone = db.Column(db.String(75),nullable=True)
    comment = db.Column(db.Text,nullable=True)
    create_date = db.Column(db.DateTime, default=datetime.utcnow())

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

in config.py:

import os
basedir = os.path.abspath(os.path.dirname(__file__))
print(basedir)

class Config(object):
    SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \
        'sqlite:///' + os.path.join(basedir, 'app.db')
    SQLALCHEMY_TRACK_MODIFICATIONS = False

I tried to specify both a direct path and a relative one. Perhaps it could have something to do with updating the macos version

1 Answers1

0

SQLalchemy made some big changes to version 1.4 that aren't yet compatible compatible with Flask SQLAlchemy. Roll back SQLAlchemy to v1.3

noslenkwah
  • 1,702
  • 1
  • 17
  • 26