sql error

Discussion in 'PHP' started by member1, Jun 19, 2007.

  1. #1
    i Create a MySQL database and i include sql table thene he give me this error

    can any one help me what wrong with this table

    Erreur
    
    requête SQL:
    
    -- --------------------------------------------------------
    -- 
    -- Table structure for table `cached`
    -- 
    CREATE TABLE `cached` (
    `id` int( 11 ) NOT NULL AUTO_INCREMENT ,
    `listingid` int( 11 ) NOT NULL default '',
    `url` char( 200 ) NOT NULL default '',
    `html` text NOT NULL ,
    `createDate` datetime NOT NULL default '0000-00-00 00:00:00',
    `modifyDate` datetime NOT NULL default '0000-00-00 00:00:00',
    PRIMARY KEY ( `id` )
    )
    
    MySQL a répondu:Documentation
    #1067 - Invalid default value for 'listingid'
    PHP:
     
    member1, Jun 19, 2007 IP
  2. Joobz

    Joobz Peon

    Messages:
    598
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I wouldn't even list a default value if you don't have one. However, you have the listingid, url and html as "NOT NULL" but you are giving them null values. You have to have some sort of default value.
     
    Joobz, Jun 19, 2007 IP
  3. MartiCode

    MartiCode Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The reason it doesn't work is that you are assigning a default varchar ('' is a string) to an integer value (listingid)
     
    MartiCode, Jun 19, 2007 IP
  4. MartiCode

    MartiCode Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    No that part is correct, '' is an empty string but not the same as NULL so it is a valid default for a NOT NULL column. The issue is with the default type (string in a int column)
     
    MartiCode, Jun 19, 2007 IP
  5. member1

    member1 Active Member

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    68
    #5
    thanks for repal me

    how i fix it
     
    member1, Jun 19, 2007 IP
  6. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #6
    Change:
    `listingid` int( 11 ) NOT NULL default '',
    Code (markup):
    To:
    `listingid` int( 11 ) NOT NULL default 0,
    Code (markup):
     
    krt, Jun 19, 2007 IP
  7. member1

    member1 Active Member

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    68
    #7
    thanks krt is work thanks
     
    member1, Jun 19, 2007 IP
  8. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #8
    the reason that changing the '' to a 0 worked is because you explicitly told mysql that the data type for listingid is an integer and then you're trying to default it to a string.
     
    ansi, Jun 19, 2007 IP