SQLite可以运行,但是PostgreSQL迁移的数据库导致错误

编程入门 行业动态 更新时间:2024-10-27 19:24:27
本文介绍了SQLite可以运行,但是PostgreSQL迁移的数据库导致错误-Django 3.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

情况

  • 我已经用几个应用程序构建了Django 3.0,PostgreSQL 11,macOS项目.
  • 我已基于以下课程,它是 github
  • 比我通过身份验证 acc
  • 创建的应用程序
  • 所有这些操作均已在 SQLite 数据库中完成
  • 以前,我已经为运行良好的早期应用程序试用了 PostgreSQL 数据库
  • 但是现在当我在settings.py文件中将 SQLite 切换为 PostgreSQL 时,错误,我尝试登录
  • 如果我将settings.py切换回 SQLite ,则一切运行正常(例如:身份验证,使用用户登录,用户自己在网站上进行操作设置)
  • 我使用decorators.py来保持登录用户的访问登录和注册页面,并且当我切换到postgresql时会出错.我在这里仅使用错误消息包含的 HttpResponse
  • I have built Django 3.0, PostgreSQL 11, macOS project with a couple of applications.
  • I have created the accounts app based on following course and it's github
  • Than I have created an application fro authentication acc
  • All this has been done in an SQLite database
  • Previously I have tried out a PostgreSQL database for the early application that was working fine
  • but now when I switch of in the settings.py file the SQLite to PostgreSQL I get an error i I try to log in
  • If I switch back the settings.py to SQLite everything works perfectly (ex.: authentication, logging in with user, user doing things on the website with it's own settings)
  • I use decorators.py to keep logged in users visiting the login and signup pages and that gives error when I switch to postgresql. I only use here HttpResponse that the error message contains

decorators.py

from django.http import HttpResponse from django.shortcuts import redirect def unauthenticated_user(view_func): def wrapper_func(request, *args, **kwargs): if request.user.is_authenticated: return redirect('home') else: return view_func(request, *args, **kwargs) return wrapper_func def allowed_users(allowed_roles=[]): def decorator(view_func): def wrapper_func(request, *args, **kwargs): group = None if request.user.groups.exists(): group = request.user.groups.all()[0].name if group in allowed_roles: return view_func(request, *args, **kwargs) else: return HttpResponse('Authorized') return wrapper_func return decorator

错误

如果我在settings.py使用 PostgreSQL 时登录.如果我注销,一切都会恢复正常.如果我使用SQL lite,则可以登录,并且一切运行正常

If I log in while settings.py uses PostgreSQL. If I log out everything works out fine again. If I use SQL lite I can log in and everything works perfectly

ValueError at / The view accounts.decorators.wrapper_function didn't return an HttpResponse object. It returned None instead. Request Method: GET Request URL: localhost... Django Version: 3.0 Exception Type: ValueError Exception Value: The view accounts.decorators.wrapper_function didn't return an HttpResponse object. It returned None instead. Exception Location: /Users/.../python3.7/site-packages/django/core/handlers/base.py in _get_response, line 126 Python Executable: /Users/.../bin/python3 Python Version: 3.7.3 ..... Request information USER MYUSERNAME GET No GET data POST No POST data FILES No FILES data COOKIES ... ...

试图解决

  • 我遵循的指南创建了在迁移后同样完成的用户组postgreSQL数据库,但在注释部分我仍然收到与USER1相同的错误.
    • 这是视频底部的推荐
    • "USER1我找到了,我忘记了更改用户的组!
    • -> USER2转到管理面板,然后在您的用户部分中将客户添加到所选的组部分中."
    • 我确实做到了这一点,但没有奏效,唯一的区别是,我使用了迁移的postgresql,并且他们使用了原始的SQLight,如果我使用的话,那么整个事情对我也适用,但是我想做到这一点使用PostgreSQL.
    • The guide that I follow created user groups that I have done as well in my migrated postgreSQL database, but I have still received the same error as USER1 in the comment section.
      • This was the recommendation in the bottom section of the video
      • "USER1 i find it, i forgot to change the user's group!
      • --> USER2 go to admin panel and in you user section add customer in the chosen group section".
      • I have done exactly that and it did not worked the only difference is that I have used a migrated postgresql and they used the original SQLight that if I use than the whole thing works for me as well, but I want to make it work with PostgreSQL.
        • 我已尝试通过 SQLite 迁移到 PostgreSQL /www.vphventures/how-to-migrate-your-django-project-from-sqlite-to-postgresql/"rel =" nofollow noreferrer>指南.
        • 我已经成功创建了SQLite数据库的副本
        • 但是当我将设置更改为postgres并尝试 python manage.py migration 时,它说正在运行的迁移:没有要应用的迁移.
        • python manage.py loaddata db.json
        • 从SQLite迁移了用户(我可以使用他们登录并像只有SQlite用户一样发生错误,如果我输错了用户名或密码不允许我进入),我看不到任何如果我使用IDE查找Postgresql中的数据表

        DoesNotExist at /register/ Group matching query does not exist.

      • 我还创建了课程负责人这样的AWS RDS postgreSQL数据库,将其迁移并连接到服务器和设置中,但仍然遇到相同的错误.
      • 我也查看了用户组权限,并且源代码SQLight数据库没有与我的postgresql一样在管理"选项卡中给出的权限
      • 创建了一个全新的Django 3项目,全新的虚拟环境0,我仅从上一个项目中复制了所有内容作为文本,从以前的数据库中迁移了所有内容,我得到了相同的错误
      • 推荐答案

        所以这是我解决的方法.

        So here is how I have solved it.

        • 当视频说我必须在管理面板中创建用户组时,我做了.
        • 我只需要向该属性添加属性.
        • 主页›身份验证和授权›组›客户
        • 添加用户允许执行的功能:
        ... accounts customer can view customer ...

        • 比我退出管理员视图
        • 我以正常方式登录,一切正常
  • 更多推荐

    SQLite可以运行,但是PostgreSQL迁移的数据库导致错误

    本文发布于:2023-10-26 23:03:19,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1531602.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:错误   数据库   SQLite   PostgreSQL

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!