OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

tables are not listing under '.table' command in sqlite3

  • Thread starter Thread starter APARNA
  • Start date Start date
A

APARNA

Guest
i'm trying to make a sqlite database connection through Flask-sqlalchemy. Code is just working fine. I can see the table contents in the visual studio code terminal.

I opened a command prompt where the below python script (name of the file is dbconnect.py) is saved and given the below things to create a table named 'Connect'. from dbconnect import app, db,Connect db.create_all() (this should create a table named 'Connect' in the database as per my knowledge).

Then I opened sqlite3.exe (same location as the python file saved) and did this. db.connect, .tables I was expecting Connect table to be listed under it. But nothing came up. I can see the data in vs code though. Where am I going wrong?

Any help would be highly obliged!.

Code:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy

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

class Connect(db.Model):
    id = db.Column(db.Integer, primary_key = True)
    name = db.Column(db.String(20),nullable = False)

with app.app_context():
    db.create_all()
    entry = Connect(name = "Apple")
    db.session.add(entry)
    db.session.commit()
    dbdata = Connect.query.all()
    print(dbdata[0])


if __name__ == '__main__':
    app.run(debug = True)
<p>i'm trying to make a sqlite database connection through Flask-sqlalchemy. Code is just working fine. I can see the table contents in the <em>visual studio code</em> terminal.</p>
<p>I opened a command prompt where the below python script (name of the file is <strong>dbconnect.py</strong>) is saved and given the below things to create a table named 'Connect'.
<code>from dbconnect import app, db,Connect</code> <code>db.create_all()</code> (this should create a table named 'Connect' in the database as per my knowledge).</p>
<p>Then I opened sqlite3.exe (same location as the python file saved) and did this.
<code> db.connect</code>,
<code>.tables</code> I was expecting Connect table to be listed under it. But nothing came up. I can see the data in vs code though. Where am I going wrong?</p>
<p><strong>Any help would be highly obliged!.</strong></p>
<pre><code>from flask import Flask
from flask_sqlalchemy import SQLAlchemy

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

class Connect(db.Model):
id = db.Column(db.Integer, primary_key = True)
name = db.Column(db.String(20),nullable = False)

with app.app_context():
db.create_all()
entry = Connect(name = "Apple")
db.session.add(entry)
db.session.commit()
dbdata = Connect.query.all()
print(dbdata[0])


if __name__ == '__main__':
app.run(debug = True)
</code></pre>
 

Latest posts

Top