FreePBX17 Error: SQLSTATE[23000]: Integrity constraint violation

Does anyone know how to fix this error in FreePBX17 when trying to add a new Trunk:

Do I need to modify the asterisk’ DB?

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘1-maxchans’ for key ‘PRIMARY’

looks like entry is present in DB already, can you share below commands output

*mysql -D asterisk -e “desc trunks;”

mysql -D asterisk -e “select trunkid,name,maxchans from trunks;”*

MariaDB [asterisk]> select trunkid,name,maxchans from trunks;
Empty set (0.000 sec)

/var/www/html/admin/modules/core/functions.inc/drivers/PJSip.class.php
        );
        // We care about the arrays later
 
        //this is really BAD, why do we always have to set to the dang _REQUESTER argh!
        if(empty($settings['codec'])) {
            $defaultCodecs = $this->freepbx->Sipsettings->getCodecs('audio');
            $settings['codecs'] = implode(",",array_keys($defaultCodecs));
        } else {
            $settings['codecs'] = implode(",",array_keys($settings['codec']));
        }
        $ins = $this->db->prepare("INSERT INTO `pjsip` (`id`, `keyword`, `data`, `flags`) VALUES ( $trunknum, :keyword, :data, 0 )");
        foreach ($settings as $k => $v) {
            // Skip this value if we don't care about it.
            if (in_array($k, $ignore) || is_array($v) || is_null($v))
                continue;
 
            // Otherwise, we can insert it.
            $ins->bindParam(':keyword', $k);
            $ins->bindParam(':data', $v);
            $ins->execute();
        }
    }
 
    /**
     * Get All Trunks
     */
    public function getAllTrunks() {
        $get = $this->db->prepare("SELECT id, keyword, data FROM pjsip as tech LEFT OUTER JOIN trunks on (tech.id = trunks.trunkid) OR (tech.id = trunks.trunkid)  where  trunks.disabled = 'off' OR trunks.disabled IS NULL");
        $get->execute();
        $result = $get->fetchAll(\PDO::FETCH_ASSOC);
        $final = array();
        foreach($result as $values) {

I just noticed that the trunk I setup is online in the Dashboard but not listed in the Trunk section.

I added a custom trunk and then a pjsip Trunk - Both show up now.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.