当尝试运行rails db:migrate时,出现上述错误。现在我很肯定我正在运行postgres,并在database.yml文件中包含以下代码。
from flask import Flask,jsonify,render_template,request
app = Flask(__name__)
if __name__ == '__main__':
app.run()
tempusage = 0
weightsusage = 0
curencyusage = 0
cost = 0
userip = '1.1.1.1'
@app.route('/tempreature/c2f/<int:temp>', methods=['GET'])
def c2f(temp):
tempreature = temp
ftemp = (tempreature * (9/5)) + 32
tempreatures = [
{
'conversionType': u'Tempreature',
'from': u'Celcius',
'fromValue':tempreature,
'to' : u'Faherenheit',
'tovalue':ftemp
}]
global userip
userip = request.environ['REMOTE_ADDR']
global tempusage
if userip == request.environ['REMOTE_ADDR']:
tempusage += 1
return jsonify({'tempreatures': tempreatures})
@app.route('/tempreature/f2c/<int:temp>', methods=['GET'])
def f2c(temp):
tempreature = (temp -32)*(5/9)
ftemp = tempreature/10
tempreatures = [
{
'conversionType': u'Tempreature',
'from': u'Faherenheit',
'fromValue':tempreature,
'to' : u'Celcius',
'tovalue':ftemp
}]
global tempusage
global userip
userip = request.environ['REMOTE_ADDR']
if userip == request.environ['REMOTE_ADDR']:
tempusage += 1
return jsonify({'tempreatures': tempreatures})
@app.route('/weight/k2p/<int:w>', methods=['GET'])
def k2p(w):
weight = w*2.205
fweight= w/10
weights = [
{
'conversionType': u'Weight',
'from': u'kg',
'fromValue':weight,
'to' : u'pounds',
'tovalue':fweight
}]
global userip
userip = request.environ['REMOTE_ADDR']
global weightsusage
if userip == request.environ['REMOTE_ADDR']:
weightsusage += 1
return jsonify({'weights': weights})
@app.route('/weight/p2k/<int:w>', methods=['GET'])
def p2k(w):
weight = w/2.205
fweight= w/10
weights = [
{
'conversionType': u'Weight',
'from': u'pounds',
'fromValue':weight,
'to' : u'kg',
'tovalue':fweight
}]
global userip
userip = request.environ['REMOTE_ADDR']
global weightsusage
if userip == request.environ['REMOTE_ADDR']:
weightsusage += 1
return jsonify({'weights': weights})
@app.route('/currency/USD/EUR/<int:value>', methods=['GET'])
def usd2e(value):
usd = value
eur = usd *0.88
cvalues = [
{
'conversionType': u'Currency',
'from': u'USD',
'fromValue':usd,
'to' : u'EUR',
'tovalue':eur
}]
global userip
userip = request.environ['REMOTE_ADDR']
global curencyusage
if userip == request.environ['REMOTE_ADDR']:
curencyusage += 1
return jsonify({'currency': cvalues})
@app.route('/currency/EUR/USD<int:value>', methods=['GET'])
def e2usd(value):
eur = value
usd = eur* 1.14
cvalues = [
{
'conversionType': u'Currency',
'from': u'EUR',
'fromValue':eur,
'to' : u'USD',
'tovalue':usd
}]
global userip
userip = request.environ['REMOTE_ADDR']
global curencyusage
if userip == request.environ['REMOTE_ADDR']:
curencyusage += 1
return jsonify({'currency': cvalues})
@app.route('/billing/', methods=['GET'])
def billing():
global userip
global cost
global tempusage
global weightsusage
global curencyusage
totalusage = tempusage + weightsusage + curencyusage
userip = request.environ['REMOTE_ADDR']
if userip == request.environ['REMOTE_ADDR']:
cost = tempusage * 0.05 + weightsusage* 0.10 + curencyusage * 0.15
return render_template('billing.html', userip = userip, tempusage = tempusage, weightusage = weightsusage, curencyusage= curencyusage, totalusage= totalusage, cost = cost)
@app.route('/useripbill/', methods=['GET'])
def totalbill():
global userip
global cost
global tempusage
global weightsusage
global curencyusage
totalusage = tempusage + weightsusage + curencyusage
userip = request.environ['REMOTE_ADDR']
cost = tempusage * 0.05 + weightsusage* 0.10 + curencyusage * 0.15
bill = [{
'userip': userip,
'tempusage': tempusage,
'weightusage':weightsusage ,
'currencyusage' : curencyusage,
'totalusage' : totalusage,
'cost':cost
}]
return jsonify({'bill': bill})
----------
我尚未设置密码。任何帮助将不胜感激。
答案 0 :(得分:3)
解决方案在注释中。在运行迁移之前,OP没有创建数据库(通过rails db:create
。