0

This is showing in my vs-studio terminal:

>>> from app import db #this command is running successful.
>>> db.create_all() # this command not running.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Python\Practice\Flask\env\lib\site-packages\flask_sqlalchemy\__init__.py", line 1039, in create_all
    self._execute_for_all_tables(app, bind, 'create_all')

  File "D:\Python\Practice\Flask\env\lib\site-packages\flask_sqlalchemy\__init__.py", line 1031, in _execute_for_all_tables
    op(bind=self.get_engine(app, bind), **extra)

  File "D:\Python\Practice\Flask\env\lib\site-packages\flask_sqlalchemy\__init__.py", line 962, in get_engine
    return connector.get_engine()

  File "D:\Python\Practice\Flask\env\lib\site-packages\flask_sqlalchemy\__init__.py", line 555, in get_engine
    options = self.get_options(sa_url, echo)

  File "D:\Python\Practice\Flask\env\lib\site-packages\flask_sqlalchemy\__init__.py", line 570, in get_options
    self._sa.apply_driver_hacks(self._app, sa_url, options)

  File "D:\Python\Practice\Flask\env\lib\site-packages\flask_sqlalchemy\__init__.py", line 883, in apply_driver_hacks
    if sa_url.drivername.startswith('mysql'):
AttributeError: 'bool' object has no attribute 'drivername'
James Z
  • 12,209
  • 10
  • 24
  • 44
Dilip Sahu
  • 11
  • 1
  • 3
  • Could you provide the code where you define `db` and `app`? – nitrovatter Mar 18 '21 at 15:59
  • app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite://///todo.db" app.config['SQLALCHEMY_DATABASE_URI'] = False app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db = SQLAlchemy(app) class Todo(db.Model): sno = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) desc = db.Column(db.String(500), nullable=False) date_created = db.Column(db.DateTime, default=datetime.utcnow) def __repr__(self) -> str: return f"{self.sno} - {self.title}" – Dilip Sahu Mar 18 '21 at 16:09
  • Why there `app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite://///todo.db"` are five `/`? It should be `app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:////todo.db"` – nitrovatter Mar 18 '21 at 16:20
  • Why do you set `SQLALCHEMY_DATABASE_URI` to `False` then? – nitrovatter Mar 18 '21 at 16:20
  • SQLALCHEMY_DATABASE_URI to False => because when, i was not using this at that time my terminal was showing command to set it TRUE or FALSE that's why i used it. – Dilip Sahu Mar 18 '21 at 18:07
  • 1
    I assume you are not right and you have received this message: `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.`. Remove this string `app.config['SQLALCHEMY_DATABASE_URI'] = False` anyway and fix the previous string also to `app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:////todo.db"` – nitrovatter Mar 18 '21 at 19:20
  • @DilipSahu Please use [edit] button, don't post your code in comments. – James Z Mar 18 '21 at 19:29
  • i followed your step, but i still got same error. – Dilip Sahu Mar 21 '21 at 06:32
  • Could you provide the code where you define `db` and `app` again? – nitrovatter Mar 21 '21 at 09:51
  • https://stackoverflow.com/q/66729624/15425742 – Dilip Sahu Mar 21 '21 at 15:42
  • https://i.stack.imgur.com/CmaU9.png – Dilip Sahu Mar 21 '21 at 15:43

1 Answers1

1

In your code:

app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite://///todo.db" app.config['SQLALCHEMY_DATABASE_URI'] = False app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

remove this line code:

app.config['SQLALCHEMY_DATABASE_URI'] = False

Try this lines of codes:

app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///todo.db' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

And for VSCode terminal:

>>> import app

>>> from app import db

>>> db.create_all()

Ole Pannier
  • 3,208
  • 9
  • 22
  • 33