Using peewee to create a table with a foreign key will report mysql 1452 error

database = MySQLDatabase('test1', user='root', host='x.x.x.x', port=3306, passwd='xxxx')

class BaseModel(Model):
    class Meta:
        database = database

class Users(BaseModel):
    name = CharField(max_length=32, null=False)
    email = CharField(max_length=64, null=True)
    phone = CharField(max_length=11, null=False)
    password = CharField(max_length=32 ,null=False)

class Groups(BaseModel):
    name = CharField(max_length=32, unique=True, null=False)

class User_group(BaseModel):
    user_id = ForeignKeyField(Users,backref='user_groups')
    group_id = ForeignKeyField(Groups,backref='user_groups')

def create_user():
    user = Users.create(name="test",email="",phone="13142134252",password="test")
    group = Groups.create(name="test")

I created a user table and a group table through peewee, and then there is a many-to-many association table user_group, I created a user test and a group test through the function create_user. I want to add a field to the user_group table. I followed the official website method. Why would I get an error?

Traceback (most recent call last):
  File "E:\OWG_devops\venv\lib\site-packages\django\core\handlers\", line 35, in inner
    response = get_response(request)
  File "E:\OWG_devops\venv\lib\site-packages\django\core\handlers\", line 128, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "E:\OWG_devops\venv\lib\site-packages\django\core\handlers\", line 126, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "E:\OWG_devops\venv\lib\site-packages\django\views\decorators\", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "E:\OWG_devops\venv\lib\site-packages\django\views\generic\", line 69, in view
    return self.dispatch(request, *args, **kwargs)
  File "E:\OWG_devops\venv\lib\site-packages\rest_framework\", line 505, in dispatch
    response = self.handle_exception(exc)
  File "E:\OWG_devops\venv\lib\site-packages\rest_framework\", line 465, in handle_exception
  File "E:\OWG_devops\venv\lib\site-packages\rest_framework\", line 476, in raise_uncaught_exception
    raise exc
  File "E:\OWG_devops\venv\lib\site-packages\rest_framework\", line 502, in dispatch
    response = handler(request, *args, **kwargs)
  File "E:\OWG_devops\OWG_devops\OWGDevops\app\", line 113, in post
    create_user(, user.get("groups"))
  File "E:\OWG_devops\OWG_devops\OWGDevops\auth\", line 6, in create_user
  File "E:\OWG_devops\venv\lib\site-packages\", line 6346, in create
  File "E:\OWG_devops\venv\lib\site-packages\", line 6556, in save
    pk = self.insert(**field_dict).execute()
  File "E:\OWG_devops\venv\lib\site-packages\", line 1907, in inner
    return method(self, database, *args, **kwargs)
  File "E:\OWG_devops\venv\lib\site-packages\", line 1978, in execute
    return self._execute(database)
  File "E:\OWG_devops\venv\lib\site-packages\", line 2745, in _execute
    return super(Insert, self)._execute(database)
  File "E:\OWG_devops\venv\lib\site-packages\", line 2474, in _execute
    cursor = database.execute(self)
  File "E:\OWG_devops\venv\lib\site-packages\", line 3157, in execute
    return self.execute_sql(sql, params, commit=commit)
  File "E:\OWG_devops\venv\lib\site-packages\", line 3151, in execute_sql
  File "E:\OWG_devops\venv\lib\site-packages\", line 2917, in __exit__
    reraise(new_type, new_type(exc_value, *exc_args), traceback)
  File "E:\OWG_devops\venv\lib\site-packages\", line 190, in reraise
    raise value.with_traceback(tb)
  File "E:\OWG_devops\venv\lib\site-packages\", line 3144, in execute_sql
    cursor.execute(sql, params or ())
  File "E:\OWG_devops\venv\lib\site-packages\MySQLdb\", line 206, in execute
    res = self._query(query)
  File "E:\OWG_devops\venv\lib\site-packages\MySQLdb\", line 319, in _query
  File "E:\OWG_devops\venv\lib\site-packages\MySQLdb\", line 259, in query
    _mysql.connection.query(self, query)
peewee.IntegrityError: (1452, 'Cannot add or update a child row: a foreign key constraint fails (`test1`.`user_group`, CONSTRAINT `user_group_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE)')

I suspect that there is any problem with my mysql, so I execute the insert command under the command line. But found that it can be inserted successfully

enter image description here

Can you give me some help, thanks in advance