Here is my OsTicket info:
osTicket Version v1.12 (a076918) — Up to date
Web Server Software Apache
MySQL Version 10.2.25
PHP Version 7.3.7

Issue:
We are getting DB Error #1062 almost daily. We believe the error is related to attachments in the tickets, but we are not exactly sure of the root cause. Here is the actual error code.

[INSERT INTO ost_attachment SET file_id = 42769, type = 'D', object_id = 277425]

Duplicate entry '277425-42769-D' for key 'file-type'<br /> <br />
---- Backtrace ----<br />
#0 (root)/include/mysqli.php(199): osTicket->logDBError('DB Error #1062', '[INSERT INTO o...')<br />
#1 (root)/include/class.orm.php(3455): db_query('INSERT INTO
os...', true, true)<br />
#2 (root)/include/class.orm.php(658): MySqlExecutor->execute()<br />
#3 (root)/include/class.attachment.php(172): VerySimpleModel->save()<br />
#4 (root)/include/ajax.draft.php(101): GenericAttachments->upload(Array)<br />
#5 (root)/include/ajax.draft.php(230): DraftAjaxAPI->_uploadInlineImage(Object(Draft))<br />
#6 (root)/include/class.dispatcher.php(145): DraftAjaxAPI->uploadInlineImageClient('277425')<br />
#7 (root)/include/class.dispatcher.php(38): UrlMatcher->dispatch('277425/attach', Array)<br />
#8 (root)/include/class.dispatcher.php(120): Dispatcher->resolve('277425/attach', Array)<br />
#9 (root)/include/class.dispatcher.php(38): UrlMatcher->dispatch('/draft/277425/a...', NULL)<br />
#10 (root)/ajax.php(50): Dispatcher->resolve('/draft/277425/a...')<br />
#11 {main}

Is anyone getting similar errors? I'm not sure if we can ignore these or if it indicates a more serious issue. Any input from the community would be appreciated.

@helpdeskguy

You can ignore them, just a warning saying it's trying to save an inline attachment (with ID of 42769) for a Draft (with ID of 277425) but there is already a record existing with that criteria.

Cheers.

    8 days later

    Is there any chance this is related to the fact that line 384 of redactor-osticket.js says:
    if (settings.url.indexOf('ajax.php/draft') != -1

    But in the code above it says ajax.draft.php?

    I know Kevin and others say I can ignore this, but the fact is this is a real database error (not a warning), and the error is appearing 5 times per day after we moved from v1.10 to v1.12. I get alerted anytime OST throws and error, so the daily flow of DB Errors is a constant reminder that something is not setup correctly.

    Is anyone else getting daily #1062 errors?

    8 days later

    Anyone?

    If no one else is experiencing this, I am going to put screen recording software on the server and see if I can view the user behavior that triggers the DB Error #1062. Can't think of any other route.

    It's just a bit annoying to see these errors popup in system email alerts on a daily basis.

    This is definitely a problem. Could you try this patch:

    diff --git a/include/class.orm.php b/include/class.orm.php
    index 3e5d666..814a7ee 100644
    --- a/include/class.orm.php
    +++ b/include/class.orm.php
    @@ -429,11 +429,7 @@ class VerySimpleModel {
    }
    // Capture the object under the object's field name
    $this->ht[$field] = $value;
    - if ($value->new)
    - // save() will be performed when saving this object
    - $value = null;
    - else
    - $value = $value->get($j['fkey'][1]);
    + $value = $value->get($j['fkey'][1]);
    // Fall through to the standard logic below
    }
    // Capture the foreign key id value
    If it still doesn't work,try this: (url made human readable: use at your own risk)

    https://docsbay.net/how-to-fix-error-1802

    1. Where I am supposed to put the code above?
    2. the docsbay link you sent refers to a 1802 error in windows??
    2 months later
    a month later

    KevinTheJedi Hi, every time i create a ticket i get this error by email also logged into OsTicket logs:

    DB Error #1062

    [INSERT INTO `LVti_thread_referral` SET `thread_id` = 158,  `object_id` = 12,  `object_type` = 'D',  `created` = NOW()] Duplicate entry '12-D-158' for key 'ref'
    
     ---- Backtrace ----
     #0 (root)/include/mysqli.php(199): osTicket->logDBError('DB Error #1062',  '[INSERT INTO `L...')
     #1 (root)/include/class.orm.php(3455): db_query('INSERT INTO `LV...',  true,  true)
     #2 (root)/include/class.orm.php(658): MySqlExecutor->execute()
     #3 (root)/include/class.thread.php(1824): VerySimpleModel->save()
     #4 (root)/include/class.thread.php(362): ThreadReferral::create(Array)
     #5 (root)/include/class.ticket.php(2602): Thread->refer(Object(Dept))
     #6 (root)/include/class.thread.php(570): Ticket->systemReferral(Array)
     #7 (root)/include/class.thread.php(844): Thread->postEmail(Array,  Object(ThreadEntry))
     #8 (root)/include/class.mailfetch.php(861): ThreadEntry->postEmail(Array)
     #9 (root)/include/class.mailfetch.php(933): MailFetcher->createTicket(1)
     #10 (root)/include/class.mailfetch.php(1013): MailFetcher->fetchEmails()
     #11 (root)/include/class.cron.php(25): MailFetcher::run()
     #12 (root)/include/class.cron.php(110): Cron::MailFetcher()
     #13 (root)/include/api.cron.php(19): Cron::run()
     #14 (root)/include/api.cron.php(40): CronApiController->run()
     #15 (root)/api/cron.php(23): LocalCronApiController::call()
     #16 {main}

    I need stop this email every time a ticket is created also because still registering this error on OsTicket error log and email every time. How i can fix this?

    The issue is realted to the object id 12? Should i remove this because maybe is no more present or in use?
    Sorry but i don't understand nothing on why i have this error when a ticket is created or a reply by email from a customer is receved and want to fix or generate error message emails that add to ticket email notifications.

    This is what i see in my database but don't know how to do and how i can fix also for future reply or ticket created

    @PeopleInside

    It looks like you have some issues with the IDs of things in your database. It appears the system is using an ID that's already in use. You will need to figure out what is duplicated, meaning either the thread_id, object_id, object_type, or all. Once you figure out which one is being duplicated you can either delete it or address the auto-increment start value.

    Cheers.

      @PeopleInside

      Also next time please do not cross post your issue. You have this comment and then a new Post opened with the same contents.

      Cheers.

      KevinTheJedi Thank you for your reply, what i can do for "figure out which one is being duplicated"?
      Seems the issue is with the object is = 12 can i remove this object? what is? Where i can remove? how to do?

      I don't know how i can fix this.

      Also next time please do not cross post your issue. You have this comment and then a new Post opened with the same contents.

      Cheers.

      Sorry about that.

      I see this:


      I can just replace on of two from 12 to 13 ?

      @PeopleInside

      Please continue this conversation in your Post here as I just realized your error of Duplicate entry '12-D-158' for key 'ref' is off-topic in this thread.

      Cheers.

      Write a Reply...