masonite icon indicating copy to clipboard operation
masonite copied to clipboard

Issue while deleting the Model using SoftDeletes

Open Bindukarkee opened this issue 2 years ago • 2 comments

Describe the bug

  • When we try to delete any data which have soft delete used in it, error occured as:

  • error: "(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE projects.id = 1' at line 1")"

Expected behaviour

No response

Steps to reproduce the bug

  • Add soft delete on your migration file and inside model

Project Model

from masoniteorm.models import Model
from masoniteorm.scopes import SoftDeletesMixin

class Project(Model, SoftDeletesMixin):
     __fillable__ = ["name", "number", "status"]
  • write a code to delete data of that model and run it

Project Controller


from masonite.controllers import Controller
from masonite.request import Request
from masonite.response import Response
from app.models.Project import Project
from masoniteorm.exceptions import QueryException

class ProjectController(Controller):

    def __init__(self, request: Request, response: Response):
        self.request = request
        self.response = response

    def delete_project(self, project_id):
        """Delete Project
        """
        try:
            project = Project.find(project_id)
            if project:
                project.delete()
            return self.response.json({"message": "Project deleted successfully!"}, 201)
        except QueryException as error:
            return self.response.json({
                "message": "Something went wrong!",
                "error": str(error)
            }, 422)
  • issue occured as:
  • error: "(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE projects.id = 1' at line 1")"

Screenshots

No response

OS

Linux

OS version

Ubuntu 18.04

Browser

Chrome

Masonite Version

4.14.3

Anything else ?

No response

Bindukarkee avatar Sep 09 '22 11:09 Bindukarkee

Can you put the whole sql generated? Try use the .to_sql() after your statement.

Marlysson avatar Sep 18 '22 15:09 Marlysson

@Bindukarkee it's working in version masonite-orm==2.18.5 can you verify your version?

yubarajshrestha avatar Sep 21 '22 01:09 yubarajshrestha

Will reopen if we get more information

josephmancuso avatar Oct 08 '22 18:10 josephmancuso