1
votes

I am getting this error in Zend Framework: Integrity constraint violation: 1048 Column 'url_id' cannot be null

My code is:

$stmt = $this->select()->where('url_address = ?', $url_address)->query();       
        $r = $stmt->fetchAll();              
        print_r($r);
        if(count($r)==0){

            $data = array(
                'url_address'      => $url_address,
            );

            $this->insert($data);       

            $stmt = $this->select()->where('url_address = ?', $url_address)->query();                               
                         $r = $stmt->fetchAll();    

        }   

        echo $r->url_id;
        return $r->url_id;
1
Did you try putting something in url_id?Ignacio Vazquez-Abrams
url_id is auto-increment, primary keyFuture King
That's not what that error is saying...Ignacio Vazquez-Abrams
I am getting error on Line 12 $r = $stmt->fetchAll();Future King
It's not an auto-increment if it's showing that errorMike B

1 Answers

-1
votes

That's a MySQL error, not really a PHP one. You need the url_id field to be a default value of NULL if nothing is going to be inserted there.