NEXTJS-无法解构“ req.body”的属性“ name”,因为它未定义。 (PATCH方式)

时间:2020-05-27 15:19:03

标签: javascript node.js reactjs next.js

我尝试从setting.js获取信息以执行PATCH方法,但出现错误。

> C:\Users\hp\PycharmProjects\business\lib\site-packages\django\db\models\base.py:320: 
RuntimeWarning: Model 'businessplan.customuser' was already registered. Reloadin
g models is not advised as it can lead to inconsistencies, most notably with related 
models.
  new_class._meta.apps.register_model(new_class._meta.app_label, new_class)
SystemCheckError: System check identified some issues:

ERRORS:
auth.User.groups: (fields.E304) Reverse accessor for 'User.groups' clashes with 
reverse accessor for 'CustomUser.groups'.
    HINT: Add or change a related_name argument to the definition for 'User.groups' or 
'CustomUser.groups'.
auth.User.user_permissions: (fields.E304) Reverse accessor for 'User.user_permissions' 
clashes with reverse accessor for 'CustomUser.user_permissions'.
    HINT: Add or change a related_name argument to the definition for 
'User.user_permissions' or 'CustomUser.user_permissions'.
businessplan.CustomUser.groups: (fields.E304) Reverse accessor for 'CustomUser.groups' 
clashes with reverse accessor for 'User.groups'.
    HINT: Add or change a related_name argument to the definition for 
'CustomUser.groups' or 'User.groups'.
businessplan.CustomUser.user_permissions: (fields.E304) Reverse accessor for 
'CustomUser.user_permissions' clashes with reverse accessor for 
'User.user_permissions'.

    HINT: Add or change a related_name argument to the definition for 
'CustomUser.user_permissions' or 'User.user_permissions'.
businessplan.CustomUser_groups: (fields.E336) The model is used as an intermediate 
model by 'businessplan.CustomUser.groups', but it does not have a foreign key to '
CustomUser' or 'Group'.
businessplan.CustomUser_user_permissions: (fields.E336) The model is used as an 
intermediate model by 'businessplan.CustomUser.user_permissions', but it does not hav
e a foreign key to 'CustomUser' or 'Permission'.
businessplan.Entrepreneur.admin: (fields.E300) Field defines a relation with model 
  'CustomUser', which is either not installed, or is abstract. 
businessplan.Projet.admin: (fields.E300) Field defines a relation with model 
  'CustomUser', 
   which is either not installed, or is abstract.

在设置中,我还有另一种PUT方法,用于更改密码。 PUT方法工作正常,但是要编辑名称和生物,我尝试使用PATCH方法,但会出错。

如何解决此问题?

下面是来自setting.js和api / user / index.js的代码

setting.js

Cannot destructure property 'name' of 'req.body' as it is undefined.

api / user / index.js

const handleSubmit = async (event) => {
    event.preventDefault();
    if (isUpdating) return;
    setIsUpdating(true);
    const formData = new FormData();
    formData.append('name', nameRef.current.value);
    formData.append('bio', bioRef.current.value);
    const res = await fetch('/api/user', {
      method: 'PATCH',
      body: formData,
    });
    if (res.status === 200) {
      const userData = await res.json();
      mutate({
        user: {
          ...user,
          ...userData.user,
        },
      });
      setMsg({ message: 'Profile updated' });
    } else {
      setMsg({ message: await res.text(), isError: true });
    }
  };

0 个答案:

没有答案