我正在尝试运行数据库并使用以下代码输入数据库来运行数据库。即使我做了正确的条目,我仍然会收到错误“没有这样的表:用户”
from flask import Flask, request, flash, url_for, redirect
from flask.ext.sqlalchemy import SQLAlchemy
from spello import app
from datetime import datetime
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///spello.db'
db = SQLAlchemy(app)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///spello.db'
db = SQLAlchemy(app)
class User(db.Model):
id = db.Column(db.Integer , primary_key = True) #defines the id
email = db.Column(db.String(90)) #defines the Developer's email ID
URL = db.Column(db.String(120)) #defines the URL
# created_on = db.Column(db.DateTime)
def __init__(self, email, URL):
self.email = email
self.URL = URL
# self.creation = datetime.now()
def __repr__(self):
return "<User %r>" % self.email
我在命令行中打开python并输入以下代码
>>> from spello import models
>>> from spello.models import db,User
>>> db.create_all()
>>> u = User('a@b.com','www.asd.com')
>>> db.session.add(u)
>>> db.session.commit()
但是当我在命令行中运行sqlite3来检查数据库是否已创建时,我收到以下错误
(spello)$ sqlite3
sqlite> select * from user;
Error: no such table: user
可以请sm1告诉我哪里出错了吗?
答案 0 :(得分:1)
sqlite3
工具的最新版本实际上是:
$ sqlite3
SQLite version 3.8.4.3 2014-04-03 16:53:12
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite>
要打开数据库,您必须实际打开它:
$ sqlite3 /wherever/you/have/put/spello.db