Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2004
    Posts
    1

    Unanswered: NOT NULL is NOT working.

    Howdy there,

    I'm trying to make a couple of columns in my table set as "NOT NULL" my create goes something like this

    create table if not exists tribe(
    tribe _id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
    language VARCHAR(20) NOT NULL,
    people VARCHAR(20),
    region VARCHAR(20),
    ......................so on and so on

    however, when i create the table, i'm still able to insert rows with no data in the NOT NULL language. so if someone forgets to insert a language in the form, it still writes a blank cell in the database.

    if i DESC the table it looks like this:
    FIELD TYPE NULL KEY DEFAULT EXTRA
    tribe_id int(11) PRI NULL auto_increment
    language varchar(20)
    people varchar(20) YES NULL
    region varchar(20) YES NULL

    I can see that they are blank in the NULL column but for TRIBE_ID, it's default is NULL and for language there is no default.

    I just want to make it so it won't write a row in the database if the user didn't enter anything for language.

    Thanks Much

    Danny M.

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    My guess is that you've got an empty string, not a NULL column. Too bad that MySQL doesn't support the CHECK constraint yet, since that would allow you to fix the problem... For now, you'll need to prevent it using web page or client side code.

    -PatP

Posting Permissions

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