小编Ron*_*nak的帖子

将模型迁移到 SQL Server 时出现 Keyerror“include”

我有一个 Django 应用程序,后端为 Microsoft sql 服务器。为此,我安装了“pip install django-mssql-backend”。

我扩展了用户模型并添加了一个额外的确认密码字段,我正在迁移,但我遇到了以下错误

Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial...Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\django\retailAudit\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\django\retailAudit\lib\site-packages\django\core\management\__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\django\retailAudit\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\django\retailAudit\lib\site-packages\django\core\management\base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\django\retailAudit\lib\site-packages\django\core\management\base.py", line 89, in wrapped
    res …
Run Code Online (Sandbox Code Playgroud)

django django-models django-mssql django-mssql-backend

4
推荐指数
1
解决办法
3423
查看次数

Django Rest 框架 - 序列化器始终返回空对象 ({})

我正在使用 django rest 框架在 django 中创建第一个rest api

我无法获取 json 格式的对象。序列化器始终返回空对象 {}

模型.py

class Shop(models.Model):
    shop_id = models.PositiveIntegerField(unique=True)
    name = models.CharField(max_length=1000)
    address = models.CharField(max_length=4000)
Run Code Online (Sandbox Code Playgroud)

序列化器.py

class ShopSerializer(serializers.ModelSerializer):
    class Meta:
        model = Shop
        fields = '__all__'
Run Code Online (Sandbox Code Playgroud)

视图.py

@api_view(['GET'])
def auth(request):
    username = request.data['username']
    password = request.data['password']
    statusCode = status.HTTP_200_OK
    try:
        user = authenticate(username=username, password=password)
        if user:
            if user.is_active:
                
                context_data = request.data
                
                shop = model_to_dict(Shop.objects.get(retailer_id = username))
                shop_serializer = ShopSerializer(data=shop)
                if shop:
                    try:
                        
                        if shop_serializer.is_valid():
                            print('is valid')
                            print(shop_serializer.data)
                            context_data = shop_serializer.data
                        else:
                            print('is …
Run Code Online (Sandbox Code Playgroud)

django django-models django-views django-serializer django-rest-framework

1
推荐指数
1
解决办法
1976
查看次数