如果您对ProgrammingError:在线程中创建的SQLite对象只能在同一线程中使用感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解ProgrammingError:在线程中创建的SQL
如果您对ProgrammingError:在线程中创建的SQLite对象只能在同一线程中使用感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解ProgrammingError:在线程中创建的SQLite对象只能在同一线程中使用的各种细节,此外还有关于Cg Programming/ProgrammableGraphics Pipeline、Django 1.8 RC1:创建数据库表时出现ProgrammingError、django 1.9:ProgrammingError:关系“users_user”不存在、django.db.utils.ProgrammingError: 1146 解决办法的实用技巧。
本文目录一览:- ProgrammingError:在线程中创建的SQLite对象只能在同一线程中使用
- Cg Programming/ProgrammableGraphics Pipeline
- Django 1.8 RC1:创建数据库表时出现ProgrammingError
- django 1.9:ProgrammingError:关系“users_user”不存在
- django.db.utils.ProgrammingError: 1146 解决办法
ProgrammingError:在线程中创建的SQLite对象只能在同一线程中使用
我是编程新手。我以前尝试过MySQL,但现在是我第一次在python
flask网站上使用SQLite。因此,也许我使用的是MySQL语法而不是SQLite,但似乎找不到问题。
Piece of my code:@app.route(''/register'', methods=[''GET'', ''POST''])def register(): form = RegisterForm(request.form) if request.method==''POST'' and form.validate(): name = form.name.data email = form.email.data username = form.username.data password = sha256_crypt.encrypt(str(form.password.data)) c.execute("INSERT INTO users(name,email,username,password) VALUES(?,?,?,?)", (name, email, username, password)) conn.commit conn.close()The error: File "C:\Users\app.py", line 59, in register c.execute("INSERT INTO users(name,email,username,password) VALUES(?,?,?,?)", (name, email, username, password)) ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 23508 and this is thread id 22640
这是否意味着我不能在HTML文件中使用名称,电子邮件用户名和密码?我该如何解决?
谢谢。
答案1
小编典典您的游标“ c”不在同一线程中创建;它可能是在Flask应用运行时初始化的。
您可能希望使用相同的方法生成SQLite对象(连接和游标),例如:
@app.route(''/'') def dostuff(): with sql.connect("database.db") as con: name = "bob" cur = con.cursor() cur.execute("INSERT INTO students (name) VALUES (?)",(name)) con.commit() msg = "Done"
Cg Programming/ProgrammableGraphics Pipeline
In the following diagrams,there is only one arrow between any two stages.However,it should be understood that GPUs usually implement the graphicspipeline with massive horizontal parallelism. Only software implementations ofthe graphics pipeline,e.g. Mesa 3D (see the Wikipedia entry),usually implement a single pipeline.
The vertex shader and fragment shader stages are discussed in more detail inthe platform-specific tutorials. The rasterization stage is discussed in Section“Rasterization” and theper-fragment operations in Section “Per-FragmentOperations”.
Vertex input parameters are defined based on the vertex data. Foreach vertex input parameter a semantic has to be defined,which specifies how the parameter relates to data in the fixed-functionpipeline. Examples of semantics are POSITION,COLOR,norMAL,TEXCOORD0,TEXCOORD1,etc. This makes it possible to use Cg programs even with APIs that wereoriginally designed for a fixed-function pipeline. For example,the vertexinput parameter for vertex positions should use the POSITION semanticsuch that all APIs can provide the appropriate data for this input parameter.Note that the vertex position is in object coordinates,i.e. this is theposition as specified in a 3D modeling tool.
Django 1.8 RC1:创建数据库表时出现ProgrammingError
我在各种项目中将AbstractBaseUser用于我的用户模型。更新到Django 1.8 RC1可以顺利进行,我可以运行migration
management命令。但是,当尝试从头开始创建新的数据库表布局时,出现以下错误:
python manage.py migrate
>>> ...
>>> ...
>>> django.db.utils.ProgrammingError: relation "auth_group" does not exist
一切都可以与Django 1.7.x完美配合,而我在其他地方都找不到关于此问题的任何信息。那么,RC1版本是否很大,还是做了一些我在Django
1.8中不知道的更改?不幸的是,该错误消息并没有真正的帮助……但是我敢肯定,它与新Django版本随附的自动迁移有关。
django 1.9:ProgrammingError:关系“users_user”不存在
1 /用psql创建一个新的数据库:@H_301_3@
create database dj_example;
2 / Installed_apps包含django.contrib.sites:@H_301_3@
DJANGO_APPS = ( 'django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.sites','django.contrib.messages','django.contrib.staticfiles','django.contrib.admin',) THIRD_PARTY_APPS = ( 'crispy_forms',# Form layouts 'allauth',# registration 'allauth.account',# registration #'allauth.socialaccount',# registration #'allauth.socialaccount.providers.twitter','djcelery',#Celery ) LOCAL_APPS = ( 'tucat.users',# custom users app }
3 / site_id设置为1@H_301_3@
SITE_ID = 1
4 /自定义用户模型过于简单:@H_301_3@
# -*- coding: utf-8 -*- from __future__ import unicode_literals,absolute_import from django.contrib.auth.models import AbstractUser class User(AbstractUser): def __unicode__(self): return self.username
5 / makemigrations工作正常@H_301_3@
# python manage.py makemigrations Migrations for 'djcelery': 0028_auto_20160601_1919.py: - Alter field status on taskMeta
6 / Migrate返回ProgrammingError:关系“users_user”不存在@H_301_3@
# python manage.py migrate Operations to perform: Apply all migrations: auth,contenttypes,djcelery,account,admin,sessions Running migrations: Rendering model states... DONE Applying account.0001_initial...Traceback (most recent call last): File "/home/antoinet/.virtualenvs/tucat/lib/python3.4/site-packages/django/db/backends/utils.py",line 64,in execute return self.cursor.execute(sql,params) psycopg2.ProgrammingError: relation "users_user" does not exist The above exception was the direct cause of the following exception: Traceback (most recent call last): File "manage.py",line 12,in <module> execute_from_command_line(sys.argv) File "/home/antoinet/.virtualenvs/tucat/lib/python3.4/site-packages/django/core/management/__init__.py",line 353,in execute_from_command_line utility.execute() File "/home/antoinet/.virtualenvs/tucat/lib/python3.4/site-packages/django/core/management/__init__.py",line 345,in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/antoinet/.virtualenvs/tucat/lib/python3.4/site-packages/django/core/management/base.py",line 348,in run_from_argv self.execute(*args,**cmd_options) File "/home/antoinet/.virtualenvs/tucat/lib/python3.4/site-packages/django/core/management/base.py",line 399,in execute output = self.handle(*args,**options) File "/home/antoinet/.virtualenvs/tucat/lib/python3.4/site-packages/django/core/management/commands/migrate.py",line 200,in handle executor.migrate(targets,plan,fake=fake,fake_initial=fake_initial) File "/home/antoinet/.virtualenvs/tucat/lib/python3.4/site-packages/django/db/migrations/executor.py",line 92,in migrate self._migrate_all_forwards(plan,full_plan,line 121,in _migrate_all_forwards state = self.apply_migration(state,migration,line 198,in apply_migration state = migration.apply(state,schema_editor) File "/home/antoinet/.virtualenvs/tucat/lib/python3.4/site-packages/django/db/backends/base/schema.py",line 90,in __exit__ self.execute(sql) File "/home/antoinet/.virtualenvs/tucat/lib/python3.4/site-packages/django/db/backends/base/schema.py",line 110,in execute cursor.execute(sql,params) File "/home/antoinet/.virtualenvs/tucat/lib/python3.4/site-packages/django/db/backends/utils.py",line 79,in execute return super(CursorDebugWrapper,self).execute(sql,params) File "/home/antoinet/.virtualenvs/tucat/lib/python3.4/site-packages/django/db/utils.py",line 95,in __exit__ six.reraise(dj_exc_type,dj_exc_value,traceback) File "/home/antoinet/.virtualenvs/tucat/lib/python3.4/site-packages/django/utils/six.py",line 685,in reraise raise value.with_traceback(tb) File "/home/antoinet/.virtualenvs/tucat/lib/python3.4/site-packages/django/db/backends/utils.py",params) django.db.utils.ProgrammingError: relation "users_user" does not exist
知道如何解决这个问题吗?@H_301_3@
解决方法
如果更改现有项目中的默认用户模型,则可能更容易丢弃所有现有迁移(和数据库)并从头开始重建.应用迁移的顺序如下:@H_301_3@
>核心django.contrib应用程序.
>您的自定义用户应用.
>其他自定义应用和第三方应用.@H_301_3@
您可以使用django-admin showmigrations
查看存在和计划的迁移.@H_301_3@
django.db.utils.ProgrammingError: 1146 解决办法
出现原因:
因为直接在mysql中删除了表或者在执行过一次迁移后,在modles中修改了表名及对应的方法和引用
产生后果:
1.迁移的过程中可能出现表不存在的报错情况
2.迁移过程没有报错,在admin管理页面点击相应的表,报错django.db.utils.ProgrammingError: 1146...
解决办法 :
1.删除migrations文件夹中除了__init__.py 文件外所有文件(pycharm环境下) 或
找到报错对应的app中的本地文件夹,删除其中migrations文件夹中除了__init__.py 和__pycache__文件夹以外所有文件(资源管理器环境下)
2.在mysql中,找到django_migrations表,删除报错app对应的行数据
如:报错app为vend则删除34行数据
3.重新迁移
python manage.py makemigrations
python manage.py migrate
关于ProgrammingError:在线程中创建的SQLite对象只能在同一线程中使用的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于Cg Programming/ProgrammableGraphics Pipeline、Django 1.8 RC1:创建数据库表时出现ProgrammingError、django 1.9:ProgrammingError:关系“users_user”不存在、django.db.utils.ProgrammingError: 1146 解决办法等相关内容,可以在本站寻找。
本文标签: