我只是尝试将我的django(1.9和python3.4)应用程序从Sqlite3迁移到Postgresql。迁移./manage.py makemigrations "app"
和./manage.py migrate
然后使用loaddata
加载所有用户后,一切似乎都找不到。但是,当我尝试使用SessionAuthentication对用户进行身份验证时,收到以下错误:
django.db.utils.IntegrityError: insert or update on table "server_gcssession" violates foreign key constraint "server_gcsses_session_id_6afc9a27_fk_django_session_session_key"
DETAIL: Key (session_id)=(b2j6ip8ac29xcvbac7ul3q1wha6mnri0) is not present in table "django_session".
在解析异常之后,似乎当具有SessionAuthentication的用户尝试通过authenticate(username,password)
和login(request,usermodel)
进行身份验证时,Session对象实际上永远不会存储在表django_sessions
中。当我尝试将用户的session_id用作以下模型的键时,抛出了Integrity异常:
class GCSSession(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL)
session =models.ForeignKey(Session)
使用此查询:
GCSSession.objects.get_or_create(
user=user,
session_id = request.session.session_key
)
用户登录时用Django信号触发的
我已经在线查看了,我发现这个问题最接近的是question。但是,我还不确定该做什么,有什么想法吗?是否有一个我错过迁移的步骤?
更新
这是使用sqlite3运行上述迁移命令的输出:
Migrations for 'server':
0001_initial.py:
- Create model ImagingUser
- Create model GCSSession
- Create model Picture
- Create model Target
Operations to perform:
Apply all migrations: server, auth, contenttypes, admin, sessions
Running migrations:
Rendering model states... DONE
Applying sessions.0001_initial... OK
Applying contenttypes.0001_initial... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0001_initial... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying server.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
这是使用postgresql运行相同命令的输出:
Migrations for 'server':
0001_initial.py:
- Create model ImagingUser
- Create model GCSSession
- Create model Picture
- Create model Target
Operations to perform:
Apply all migrations: sessions, auth, admin, contenttypes, server
Running migrations:
No migrations to apply.