我克隆了一个来自github的回购并正在研究它.该项目在django并使用postgres作为数据库.该项目现在处于生产阶段,我需要对其进行一些更改.数据库规格是:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
# Or path to database file if using sqlite3.
'NAME': 'project_name',
'USER': 'admin',
'PASSWORD': '',
# Empty for localhost through domain sockets or '127.0.0.1'
# for localhost through TCP.
'HOST': 'localhost',
'PORT': '5432',
}
}
Run Code Online (Sandbox Code Playgroud)
我想在我的本地主机上运行它,但我无法.我收到错误:
django.db.utils.OperationalError: fe_sendauth: no password supplied
Run Code Online (Sandbox Code Playgroud)
我已经搜索过这个问题,但找不到可以帮助我的解决方案.谁能告诉我问题出在哪里?
我在Apache下有一个Flask服务器,我用它作为应用程序的Rest API,当服务器运行2-3天时它突然停止工作并加注OperationalError: MySQL Connection not available.
错误总是发生在login
方法中,因为它是应用程序打开时首先调用的(但所有方法都遵循相同的模式).
这是login
方法:
@app.route(LOGIN_API_URL, methods=['POST'])
def login():
if (request.method == 'POST'):
cursor = connection.cursor(buffered=True, dictionary=True)
cursor.execute('select * from users where username = %s', (request.form['username'],))
user = cursor.fetchone()
if user is None or user['password'] != str(request.form['password']):
abort(403)
else:
cursor.execute('update users set last_login = (%s) where user_id = %s', str(int(round(time.time() * 1000))), user['user_id'],)
utils.safe_commit(connection, cursor)
return utils.sanitize_response({'status':200, 'message':'Logged in'})
Run Code Online (Sandbox Code Playgroud)
无论safe_commit
与sanitize_response
如下:
def sanitize_response(response, is_array=False):
if response is …
Run Code Online (Sandbox Code Playgroud) 我使用sqlite(v2.6.0)作为数据库后端并使用sqlalchemy(v0.7.9)来操作它.最近我收到了一个错误OperationalError: (OperationalError) database is locked
通过搜索stackoverflow,可能的解决方案是增加连接的超时.Referece:OperationalError:数据库被锁定
但我不知道如何在sqlalchemy中做到这一点(因为连接实际上是由它控制的)有人可以给我一个方向吗?
嗨,我正在做djangogirls教程,并遇到了OperationalError没有这样的表:blog_post.这在我的虚拟环境中工作得很好,但在推送到heroku之后我得到了OperationalError.
我正在使用Django 1.7.7.有关错误的更多信息,请访问:https://girlsblog.herokuapp.com/
我
python manage.py makemigrations
python manage.py migrate
最初是在本教程的开头做的.然后我尝试再次执行此操作,并且"未检测到任何更改"和"无需迁移"
这是我的post_list.html
{% extends 'blog/base.html' %}
{% block content %}
{% for post in posts %}
<div class="post">
<div class="date">
{{ post.published.date }}
</div>
<h1><a href="{% url 'blog.views.post_detail' pk=post.pk %}">{{ post.title }}</a></h1>
<p> {{ post.text|linebreaks }}</p>
</div>
{% endfor %}
{% endblock content %}
Run Code Online (Sandbox Code Playgroud)
这是我的.gitignore
myvenv
__pycache__
staticfiles
local_settings.py
db.sqlite3
Run Code Online (Sandbox Code Playgroud)
Models.py
from django.db import models
from django.utils import timezone
# Create your models here.
class Post(models.Model):
author …
Run Code Online (Sandbox Code Playgroud) 我在python中使用sqlalchemy包.在现有表上执行自动加载后,我的操作需要一些时间才能执行.当我尝试使用连接时,这会导致以下错误:
sqlalchemy.exc.OperationalError: (OperationalError) (2006, 'MySQL server has gone away')
Run Code Online (Sandbox Code Playgroud)
我有一个简单的实用程序函数执行多次插入:
def insert_data(data_2_insert, table_name):
engine = create_engine('mysql://blah:blah123@localhost/dbname')
# Metadata is a Table catalog.
metadata = MetaData()
table = Table(table_name, metadata, autoload=True, autoload_with=engine)
for c in mytable.c:
print c
column_names = tuple(c.name for c in mytable.c)
final_data = [dict(zip(column_names, x)) for x in data_2_insert]
ins = mytable.insert()
conn = engine.connect()
conn.execute(ins, final_data)
conn.close()
Run Code Online (Sandbox Code Playgroud)
由于'data_2_insert'有677,161行,所以执行时间很长的是以下行.
final_data = [dict(zip(column_names, x)) for x in data_2_insert]
Run Code Online (Sandbox Code Playgroud)
我遇到了这个问题,提到了类似的问题.但是我不确定如何实现接受的答案建议的连接管理,因为robots.jpg在评论中指出了这一点:
SQLAlchemy 0.7的注意事项 - 不推荐使用PoolListener,但可以使用新的事件系统 …
我在Django遇到了一个与DB有关的问题,我不明白.
我定义了一个MPTT模型:
class Image(MPTTModel):
name = models.CharField(max_length=50)
parent = TreeForeignKey('self', null=True, blank=True, related_name='children')
def __unicode__(self):
return self.name
def rank(self): leaves = self.get_leafnodes() if leaves: rank = leaves[0].get_level() - self.get_level() else: rank = 0 return rank
mptt.register(Image, order_insertion_by=['name'])
Run Code Online (Sandbox Code Playgroud)
然后在我的视图中,我尝试使用模型的一些语句,并得到一个OperationalError.
def index(request):
if request.method == 'POST':
image_string = request.POST.get('get_image')
index = image_string.find('(')
if index == -1:
parent = image_string
child = None
else:
parent = image_string[0:index]
child = image_string[index+1:len(image_string)-1]
try:
images = Image.objects.all()
image_names = [a.name for a in images]
except Image.DoesNotExist: …
Run Code Online (Sandbox Code Playgroud) 我在简单的 django 程序运行中得到这个错误.. OperationalError at /admin/blog/post/ no such table: blog_post
django ×4
python ×3
mysql ×2
sqlalchemy ×2
sqlite ×2
apache ×1
django-mptt ×1
flask ×1
git ×1
postgresql ×1