Advanced Search

Results 1 to 7 of 7

Thread: MySQL Error Handling

  1. #1
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default MySQL Error Handling

    Hello O' MySQL Wise Ones...

    I'm entering the following MySQL string into my databse to create a new table:


    Code:
    CREATE TABLE auth (
      userid
        int(4)
        unsigned
        zerofill
        DEFAULT '0000'
        NOT NULL
        auto_increment,
      username varchar(20),
      userpassword varchar(20),
      PRIMARY KEY (userid)
    );
    And I get this error when I try to do so:
    #1067 - Invalid default value for 'userid'

    I know nothing about MySQL so any help is appreciated. I got that MySQL query from an online tutorial.

    Thanks a million!

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    '0000' is a string, not an integer. userid has been specified as an integer field. Just do:
    Code:
        DEFAULT 0
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Thanks for the reply!

    I did what you said but I'm still getting the same error. What else could be at issue?

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    That's the only issue that it could be, if it is giving the exact same error. Make sure your query is like this:

    Code:
    CREATE TABLE auth (
      userid
        int(4)
        unsigned
        zerofill
        DEFAULT 0
        NOT NULL
        auto_increment,
      username varchar(20),
      userpassword varchar(20),
      PRIMARY KEY (userid)
    );
    If it is, make sure that you are in fact getting the same error message.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    I copied and pasted the code you provided...still getting the same EXACT error.

    Here is a screenshot of the error page:

  6. #6
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    You cannot have a default value: the column is auto-incremented.
    Mike

  7. #7
    Join Date
    Oct 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Creating a new Table in MySQL
    Following is the absolute minimum required to create a new table in MySQL:

    CREATE TABLE tbl_name
    [(create_definition, ...)] [table_options]
    The complete syntax is pretty long actually and I'd suggest that you consult MySQL documentation for that. Here is the CREATE TABLE command that we are going to use to create a "users" table with 4 fields in the "examples" database we just created:

    CREATE TABLE users (
    user_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    first_name TINYTEXT NOT NULL,
    last_name TINYTEXT NOT NULL,
    country_code CHAR(2) NULL
    );
    Last edited by ddadmin; 10-09-2007 at 02:39 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •