#1067 - Invalid default value for 'membership' - mysql

I am using a SQL file included in my program and once I fixed an issue that I was able to find the answer to in here (THANK YOU).. I ran it again and got the following error:
SQL query:
# Create table structure for 'member' table
CREATE TABLE member(
memberID INT( 11 ) NOT NULL AUTO_INCREMENT ,
title VARCHAR( 80 ) NOT NULL DEFAULT '',
firstname VARCHAR( 80 ) NOT NULL DEFAULT '',
lastname VARCHAR( 80 ) NOT NULL DEFAULT '',
email VARCHAR( 80 ) NOT NULL DEFAULT '',
address VARCHAR( 80 ) NOT NULL DEFAULT '',
suburb VARCHAR( 80 ) NOT NULL DEFAULT '',
state VARCHAR( 80 ) NOT NULL DEFAULT '',
country VARCHAR( 80 ) NOT NULL DEFAULT '',
postcode VARCHAR( 11 ) NOT NULL DEFAULT '',
mobile VARCHAR( 80 ) NOT NULL DEFAULT '',
phone VARCHAR( 80 ) NOT NULL DEFAULT '',
fax VARCHAR( 80 ) NOT NULL DEFAULT '',
membership INT( 2 ) NOT NULL DEFAULT '',
payment INT( 2 ) NOT NULL DEFAULT '',
startdate BIGINT( 14 ) NOT NULL DEFAULT 0,
enddate BIGINT( 14 ) NOT NULL DEFAULT 0,
userID INT( 11 ) NOT NULL ,
PRIMARY KEY ( memberID ) ,
UNIQUE (
memberID
)
) ENGINE = MYISAM ;
MySQL said:
#1067 - Invalid default value for 'membership'
What do I need to change to make this work ? this is an older script, but I am not knowledgeable enough to know what needs to be changed for MySQL 5.5 version.
Thank you so much for your help!
And I'm sure there will be other errors popping up after I fix this one..

The membership column is an int, but you're giving it a default string value of ''. So change
membership INT( 2 ) NOT NULL DEFAULT '',
to
membership INT( 2 ) NOT NULL DEFAULT 0,
(0 or whatever default value you want for that field.)

I was getting:
Incorrect integer value: '' for column 'column_name' at row 1
I've fixed it editing /etc/mysql/my.cnf or /etc/mysql/mysql.conf.d/mysqld.cnf files. Then find the following line:
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
and replace it for
sql-mode=""
and restart MySQL: service mysql restart

Related

Database not importing

Error
##
--
-- Database: verticalned
-- --------------------------------------------------------
-- Table structure for table announcements
CREATE TABLE `announcements` (
`id` INT( 10 ) NOT NULL ,
`description` VARCHAR( 6000 ) DEFAULT NULL ,
`links` VARCHAR( 100 ) DEFAULT NULL ,
`first` TINYINT( 1 ) DEFAULT > NULL ,
`second` TINYINT( 1 ) DEFAULT NULL ,
`third` TINYINT( 1 ) DEFAULT NULL ,
`fourth` TINYINT( 1 ) DEFAULT NULL ,
`staff` VARCHAR( 22 ) DEFAULT NULL ,
`time` DATETIME( 2 ) DEFAULT NULL ,
`subject` VARCHAR( 100 ) DEFAULT NULL
) ENGINE = INNODB DEFAULT CHARSET = latin1;
MySQL said: Documentation
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
near '(2) DEFAULT NULL, subject varchar(100) DEFAULT NULL )
ENGINE=InnoDB DEFAULT ' at line 20
version
Looks like the mysql version you are using (probably older than 5.6.4) does not accept precision (fractional seconds). You can bypass the issue by replacing ..., time DATETIME(2) DEFAULT NULL ,... with ... , time DATETIME DEFAULT NULL ,....
However, you should solve the issue by either changing the data type to timestamp or upgrading MySQL server to a version later than 5.6.4
CREATE TABLE `announcements` (
`id` INT(10) NOT NULL,
`description` VARCHAR(6000) DEFAULT NULL,
`links` VARCHAR(100) DEFAULT NULL,
`first` TINYINT( 1 ) DEFAULT NULL ,
`second` TINYINT( 1 ) DEFAULT NULL ,
`third` TINYINT( 1 ) DEFAULT NULL ,
`fourth` TINYINT( 1 ) DEFAULT NULL ,
`staff` VARCHAR( 22 ) DEFAULT NULL ,
`time` DATETIME( 2 ) DEFAULT NULL ,
`subject` VARCHAR( 100 ) DEFAULT NULL
) ENGINE = INNODB DEFAULT CHARSET = latin1;
obvoiusly theres nothing wrongn with your code. just add the slanted quotes
CREATE TABLE announcements (
id INT NOT NULL ,
description VARCHAR( 6000 ) DEFAULT NULL ,
links VARCHAR( 100 ) DEFAULT NULL ,
firstTINYINT DEFAULT NULL ,
secondTINYINT DEFAULT NULL,
thirdTINYINT DEFAULT NULL ,
fourthTINYINT DEFAULT NULL,
staffVARCHAR(22) DEFAULT NULL ,
timeDATETIME DEFAULT NULL ,
subject` VARCHAR( 100 ) DEFAULT NULL
) ENGINE = INNODB DEFAULT CHARSET = latin1;
Please remove character number from INT and TINYINT, and add the slanted quotes your code should work.

I have exported a Mysql Database, and am having syntax issues importing to a newer version

I am trying to import a Mysql DB into a new instance on an updated domain. I am getting the below syntax error, I cant work out what is wrong and everythig I try isnt working.
can you help?
SQL query:
--
-- Database: 'pringlerfe'
-- -- --------------------------------------------------------
--
-- Table structure for table `adverts`
--
CREATE TABLE `adverts` (
`advers_id` INT( 11 ) NOT NULL ,
`advers_name` VARCHAR( 50 ) DEFAULT NULL ,
`advers_sqimg` VARCHAR( 50 ) DEFAULT NULL ,
`advers_squrl` VARCHAR( 100 ) DEFAULT NULL ,
`advers_towerimg` VARCHAR( 50 ) DEFAULT NULL ,
`advers_url` VARCHAR( 100 ) DEFAULT NULL ,
`advers_des` VARCHAR( 100 ) DEFAULT NULL ,
`advers_display` VARCHAR( 50 ) DEFAULT NULL
) ENGINE = MYISAM DEFAULT CHARSET = latin1;
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '
--
-- Table struc' at line 3 `
CREATE TABLE adverts (
advers_id int NOT NULL,
advers_name varchar( 50 ) DEFAULT NULL,
advers_sqimg VARCHAR( 50 ) DEFAULT NULL,
advers_squrl VARCHAR( 100 ) DEFAULT NULL,
advers_towerimg VARCHAR( 50 ) DEFAULT NULL,
advers_url VARCHAR( 100 ) DEFAULT NULL,
advers_des VARCHAR( 100 ) DEFAULT NULL,
advers_display VARCHAR( 50 ) DEFAULT NULL
);

Table Creation Error [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Looking to fix the syntax error
Error Message:
force int(9) NOT NULL default '0', perm tinyint(1) NOT NULL default
'0', act' at line 11
My Table Syntax:
CREATE TABLE `ttp_sites` (
siteid int( 4 ) NOT NULL AUTO_INCREMENT ,
wname char( 64 ) NOT NULL default '',
email char( 64 ) NOT NULL default '',
siteurl char( 255 ) NOT NULL default '',
sitename char( 128 ) NOT NULL default '',
furl char( 255 ) NOT NULL default '',
icqnumb char( 20 ) default '',
icqname char( 20 ) default '',
sent int( 9 ) NOT NULL default '0',
FORCE int( 9 ) NOT NULL default '0',
perm tinyint( 1 ) NOT NULL default '0',
active tinyint( 1 ) NOT NULL default '0',
manage_type tinyint( 1 ) NOT NULL default '0',
send_ratio int( 4 ) NOT NULL default '0',
PRIMARY KEY ( siteid ) ,
KEY siteurl( siteurl ) ,
KEY sitename( sitename ) ,
KEY active( active )
) ENGINE = MYISAM DEFAULT CHARSET = latin1 AUTO_INCREMENT =1;
The issue with your code is you have used a reserved keyword FORCE , you can use the reserve keyword to create a table column name is by giving the name within single quotes which takes the keyword as a name.
CREATE TABLE `ttp_sites` (
siteid int( 4 ) NOT NULL AUTO_INCREMENT ,
wname char( 64 ) NOT NULL default '',
email char( 64 ) NOT NULL default '',
siteurl char( 255 ) NOT NULL default '',
sitename char( 128 ) NOT NULL default '',
furl char( 255 ) NOT NULL default '',
icqnumb char( 20 ) default '',
icqname char( 20 ) default '',
sent int( 9 ) NOT NULL default '0',
`FORCE` int( 9 ) NOT NULL default '0',
perm tinyint( 1 ) NOT NULL default '0',
active tinyint( 1 ) NOT NULL default '0',
manage_type tinyint( 1 ) NOT NULL default '0',
send_ratio int( 4 ) NOT NULL default '0',
PRIMARY KEY ( siteid ) ,
KEY siteurl( siteurl ) ,
KEY sitename( sitename ) ,
KEY active( active )
) ENGINE = MYISAM DEFAULT CHARSET = latin1 AUTO_INCREMENT =1;
Sql Fiddle
P.s : Don't use keyword for naming a column.
Updated Query of your's in the comment
CREATE TABLE ttp_traffic
( siteid int(4) NOT NULL default '0',
ipaddr char(25) NOT NULL default '',
click int(3) NOT NULL default '0',
prox int(1) NOT NULL default '0',
refer char(255) NOT NULL default '',
datev timestamp NOT NULL,
KEY siteid (siteid),
KEY datev (datev),
KEY click (click),
KEY ipaddr (ipaddr) )ENGINE = MYISAM;
Timestamp should not have datatype size that was the error in your code
SQl Fiddle

Syntax error in create table query

I cant get this syntax error.
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(id) ENGINE=MyISAM)' at line 15
CREATE TABLE IF NOT EXISTS `destination_cdr` (
`id` BIGINT( 20 ) NOT NULL AUTO_INCREMENT ,
`calldate` DATETIME NOT NULL ,
`source` VARCHAR( 80 ) NOT NULL ,
`destination` VARCHAR( 80 ) NOT NULL ,
`account_code` VARCHAR( 30 ) DEFAULT NULL ,
`pincode` VARCHAR( 45 ) NOT NULL ,
`duration_call` BIGINT( 20 ) NOT NULL DEFAULT '0',
`duration_talk` BIGINT( 20 ) NOT NULL ,
`disposition` VARCHAR( 255 ) NOT NULL ,
`clid` VARCHAR( 80 ) DEFAULT NULL ,
`cdr_id` BIGINT( 20 ) DEFAULT NULL ,
`vxcdr_id` BIGINT( 20 ) DEFAULT NULL ,
`provider` INT( 11 ) NOT NULL DEFAULT '0' PRIMARY KEY ( `id` )) ENGINE = MYISAM
;
You need a commma between provider and primary Key:
`provider` INT( 11 ) NOT NULL DEFAULT '0', PRIMARY KEY ( `id` )) ENGINE = MYISAM
Missing comma before primary key clause.
`provider` INT( 11 ) NOT NULL DEFAULT '0', PRIMARY KEY ( `id` ))
Error
SQL query:
--
-- Database: wadud
--
-- Table structure for table destination
CREATE TABLE destination (
id bigint(20) NOT NULL,
country varchar(255) NOT NULL,
photo text NOT NULL,
tours varchar(255) NOT NULL,
created_at timestamp NULL DEFAULT NULL,
updated_at timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
MySQL said: Documentation
1050 - Table 'destination' already exists

Error 1064 in SQL Code

I used the phpMyAdmin form to create a table, i.e. I filled in the fields and it generated the code. The code generated doesn't work, but I can't find the error. Any help would be appreciated.
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '( 1 ) NOT NULL DEFAULT '0',
userEmail VARCHAR( 255 ) NOT NULL ,PRIMARY KEY (' at line 14
Here's the code:
CREATE TABLE members (
userID INT( 9 ) NOT NULL AUTO_INCREMENT ,
userName VARCHAR( 15 ) NOT NULL ,
userPwd VARCHAR( 16 ) NOT NULL ,
userTitle VARCHAR( 4 ) NOT NULL ,
fName VARCHAR( 30 ) NOT NULL ,
lName VARCHAR( 30 ) NOT NULL ,
address VARCHAR( 255 ) NULL ,
dateOfBirth VARCHAR( 10 ) NULL ,
userJob VARCHAR( 15 ) NULL ,
regDate VARCHAR( 20 ) NOT NULL ,
accType CHAR( 1 ) NOT NULL DEFAULT 'F',
regCode VARCHAR( 255 ) NOT NULL ,
isActivated BOOL( 1 ) NOT NULL DEFAULT '0',
userEmail VARCHAR( 255 ) NOT NULL ,
PRIMARY KEY ( userID ) ,
UNIQUE (userName ,userEmail)
) ENGINE = MYISAM
mysql ver 5.1 php ver 5.2.*
You cannot use BOOL(1)
Try the following (i just replaced BOOL(1) with BOOL)
BOOL and BOOLEAN are synonyms for TINYINT(1).
CREATE TABLE members (
userID INT( 9 ) NOT NULL AUTO_INCREMENT ,
userName VARCHAR( 15 ) NOT NULL ,
userPwd VARCHAR( 16 ) NOT NULL ,
userTitle VARCHAR( 4 ) NOT NULL ,
fName VARCHAR( 30 ) NOT NULL ,
lName VARCHAR( 30 ) NOT NULL ,
address VARCHAR( 255 ) NULL ,
dateOfBirth VARCHAR( 10 ) NULL ,
userJob VARCHAR( 15 ) NULL ,
regDate VARCHAR( 20 ) NOT NULL ,
accType CHAR( 1 ) NOT NULL DEFAULT 'F',
regCode VARCHAR( 255 ) NOT NULL ,
isActivated BOOL NOT NULL DEFAULT '0',
userEmail VARCHAR( 255 ) NOT NULL ,
PRIMARY KEY ( userID ) ,
UNIQUE (userName ,userEmail)
) ENGINE = MYISAM
Change
isActivated BOOL( 1 ) NOT NULL DEFAULT '0',
to
isActivated BOOL NOT NULL DEFAULT '0',
you can read about it more : here
M indicates the maximum display width for integer types
Bool does not have this so you can't specify width. it's always 1