I have been having this reoccurring problem when attempting to import a .sql file into MySQL, Here is what I get
ERROR
SQL Query:
CREATE TABLE `ADMINS` (
`id` int(11) NOT NULL auto_increment,
`client_id` varchar(80) NOT NULL default '',
`client_pw` varchar(16) default NULL,
`client_school` varchar(16) default NULL,
`client_expdate` date default '0000-00-00',
`client_fullname` varchar(50) default NULL,
`webinfo` mediumtext,
`webinfodate` date default NULL,
`LastUpdate` timestamp(14) NOT NULL,
`user_activation_key` varchar(60) default NULL,
`user_email` varchar(100) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=2 ;
MySQL Said:
#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 '(14) NOT NULL,
`user_activation_key` varchar(60) default NULL,
`user_email' at line 10
Timestamps don't have lengths. Change:
timestamp(14)
to
timestamp
The syntax is not correct, as pointed by John you do not need to the length for timestamp datatype. In addition type=myisam is deprecated and its engine=myisam now.
CREATE TABLE `ADMINS` (
`id` int(11) NOT NULL auto_increment,
`client_id` varchar(80) NOT NULL default '',
`client_pw` varchar(16) default NULL,
`client_school` varchar(16) default NULL,
`client_expdate` date default '0000-00-00',
`client_fullname` varchar(50) default NULL,
`webinfo` mediumtext,
`webinfodate` date default NULL,
`LastUpdate` timestamp NOT NULL,
`user_activation_key` varchar(60) default NULL,
`user_email` varchar(100) NOT NULL default '',
PRIMARY KEY (`id`)
) engine=MyISAM AUTO_INCREMENT=2 ;
Related
CREATE DATABASE vehicle_system;
USE vehicle_system;
USE vehicle_system; CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(250) DEFAULT NULL,
`email` varchar(255) NOT NULL,
`password_hash` text NOT NULL,
`api_key` varchar(32) NOT NULL,
`phone` varchar(14) NOT NULL,
`status` int(1) NOT NULL DEFAULT '1',
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`),
UNIQUE KEY `phone` (`phone`)
);
CREATE TABLE IF NOT EXISTS `vehicle_model` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(250) DEFAULT NULL,
`manufacturer_id` int(11) NOT NULL,
`manufacturer_name` varchar(250) NOT NULL,
`model` varchar(32) NOT NULL,
`model_no` varchar(32) NOT NULL,
`type` varchar(32) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `manufacturer_id` (`manufacturer_id`)
);
CREATE TABLE IF NOT EXISTS `user_vehicles` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(250) DEFAULT NULL,
`user_id` int(11) NOT NULL,
`manufacturer_id` int(11) NOT NULL,
`vehicle_no` varchar(32) NOT NULL,
`rc_no` text,
`engine_type` varchar(32),
`year` int(4),
`insurance_exp_date` timestamp,
`pollution_exp_date` timestamp,
`rc_renew_date` timestamp,
`insurance_company` varchar(32),
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `vehicle_no` (`vehicle_no`),
KEY `user_id` (`user_id`),
KEY `manufacturer_id` (`manufacturer_id`)
);
While executing above query I get
#1293 - Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
But I do not see two default time stamp in the query, Can any one point out what could be the possible error. Is it because current time stamp is present in the users table ? If so how to get rid of this ?
I think the problem is that you do not have a default for all the fields of type timestamp.
Running your query I got the following error:
Error Code: 1067. Invalid default value for 'updated_at'
Then I got:
Error Code: 1067. Invalid default value for 'pollution_exp_date'
Everything works fine when all the timestamp field have a default value:
CREATE DATABASE vehicle_system;
USE vehicle_system;
USE vehicle_system; CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(250) DEFAULT NULL,
`email` varchar(255) NOT NULL,
`password_hash` text NOT NULL,
`api_key` varchar(32) NOT NULL,
`phone` varchar(14) NOT NULL,
`status` int(1) NOT NULL DEFAULT '1',
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`),
UNIQUE KEY `phone` (`phone`)
);
CREATE TABLE IF NOT EXISTS `vehicle_model` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(250) DEFAULT NULL,
`manufacturer_id` int(11) NOT NULL,
`manufacturer_name` varchar(250) NOT NULL,
`model` varchar(32) NOT NULL,
`model_no` varchar(32) NOT NULL,
`type` varchar(32) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `manufacturer_id` (`manufacturer_id`)
);
CREATE TABLE IF NOT EXISTS `user_vehicles` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(250) DEFAULT NULL,
`user_id` int(11) NOT NULL,
`manufacturer_id` int(11) NOT NULL,
`vehicle_no` varchar(32) NOT NULL,
`rc_no` text,
`engine_type` varchar(32),
`year` int(4),
`insurance_exp_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`pollution_exp_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`rc_renew_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`insurance_company` varchar(32),
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `vehicle_no` (`vehicle_no`),
KEY `user_id` (`user_id`),
KEY `manufacturer_id` (`manufacturer_id`)
);
This is on MySql 5.7.10.
There is an interesting discussion on this here:
https://bugs.mysql.com/bug.php?id=41137
Creation of timestamp fields is different from any other!
Practically up to 5.6.6 you do not have to declare NOT NULL as by definition that field is NOT NULL and with neither DEFAULT nor ON UPDATE clauses, it is the same as DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP.
After 5.6.6 you have to explicit defaults. Look also:
https://dev.mysql.com/doc/refman/5.5/en/timestamp-initialization.html
and
http://dev.mysql.com/doc/refman/5.7/en/timestamp-initialization.html
Finally, in your case removing NOT NULL is the best approach.
Regards
I am trying to create some tables on phpMyAdmin, but when I use the code below I am getting this 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 '(32) NOT NULL,
activated enum(0,1) NOT NULL,
PRIMARY KEY (id)
) E' at line 8
Here is my code:
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`first_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`sign_up_date` date(32) NOT NULL,
`activated` enum(`0`,`1`) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=1atin1 AUTO_INCREMENT=1 ;
Try following code. I have resolved your mistakes in code
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`first_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`sign_up_date` date NOT NULL,
`activated` enum('0','1') NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
DATE data type takes no length
`sign_up_date` DATE NOT NULL
I keep on getting the below error message when I try to enter some important records I accentually deleted.
Duplicate entry 'EMIR2023 ' for key 'flightNo'
Is there a way in the phpMyAdmin environment I can disable the UNIQUE KEY then activate it when I am done with inserting the records?
Find below the structure of my table, I hope it helps
--
-- Table structure for table `flightSched`
--
CREATE TABLE IF NOT EXISTS `flightSched` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`timePeriod` time DEFAULT '00:00:00',
`depOrArriv` varchar(9) DEFAULT NULL,
`flightNo` varchar(9) NOT NULL,
`airline` varchar(20) DEFAULT NULL,
`dest` varchar(30) DEFAULT NULL,
`origin` varchar(30) DEFAULT NULL,
`depature` time DEFAULT '00:00:00',
`don` set('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday') DEFAULT NULL,
`arrivalTime` datetime DEFAULT '0000-00-00 00:00:00',
`arrivalTimeSec` varchar(28) DEFAULT NULL,
`status` varchar(15) NOT NULL,
`image_type` varchar(25) DEFAULT NULL,
`image` blob NOT NULL,
`image_size` varchar(25) DEFAULT NULL,
`image_name` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `flightNo` (`flightNo`),
UNIQUE KEY `arrivalTime_2` (`arrivalTime`),
KEY `arrivalTime` (`arrivalTime`),
KEY `arrivalTime_3` (`arrivalTime`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=537 ;
Looking forward to your reply :-)
Try unique_checks
SET unique_checks=0;
... import operation ...
SET unique_checks=1;
check reference
I have a very strange problem here. I am exporting a query through phpmyadmin and then when I run it using mysql_query I get an error saying that syntax of the query isn't correct.
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 'CREATE TABLE IF NOT EXISTS `wp_cfs_events` ( `event_id` int(11) NOT NULL AUTO_' at line 14
The same query runs perfectly fine using phpmyadmin. What could be the problem?
Here is the SQL query
CREATE TABLE IF NOT EXISTS `wp_cfs_certificates` (
`certificate_id` varchar(8) DEFAULT NULL,
`parent_name` varchar(45) NOT NULL,
`address` varchar(45) NOT NULL,
`phone_number` varchar(15) NOT NULL,
`emergency_number` varchar(15) NOT NULL,
`email` varchar(45) NOT NULL,
`certificate_price` enum('40','50') NOT NULL,
`certificate_order_time` datetime DEFAULT NULL,
`is_used` tinyint(1) DEFAULT '0',
UNIQUE KEY `certificate_id_UNIQUE` (`certificate_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `wp_cfs_events` (
`event_id` int(11) NOT NULL AUTO_INCREMENT,
`event_name` varchar(60) DEFAULT NULL,
`event_desc` varchar(2048) DEFAULT NULL,
`event_date` date DEFAULT NULL,
PRIMARY KEY (`event_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
INSERT INTO `wp_cfs_events` (`event_id`, `event_name`, `event_desc`, `event_date`) VALUES
(1, 'Culture Night', 'all about culture', '2013-05-16'),
(2, 'Sports Night', 'all about sports', '2013-05-31'),
(3, 'Random Night', 'randomness overloaded', '2013-06-15'),
(4, 'Winter Fest', 'the awesome winter fest', '2013-11-20'),
(5, 'Archived Event', 'this event has been occured in past', '2013-04-02');
CREATE TABLE IF NOT EXISTS `wp_cfs_parents` (
`parent_id` int(11) NOT NULL,
`parent_name` varchar(60) DEFAULT NULL,
PRIMARY KEY (`parent_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `wp_cfs_registrations` (
`registration_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`certificate_id` varchar(8) NOT NULL,
`event_id` varchar(45) DEFAULT NULL,
`parent_name` varchar(45) NOT NULL,
`address` varchar(45) NOT NULL,
`phone_number` varchar(15) NOT NULL,
`emergency_number` varchar(15) NOT NULL,
`email` varchar(45) NOT NULL,
`child_name` varchar(45) DEFAULT NULL,
`child_age` int(11) DEFAULT NULL,
PRIMARY KEY (`registration_id`),
UNIQUE KEY `certificate_id_UNIQUE` (`certificate_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
ALTER TABLE `wp_cfs_registrations`
ADD CONSTRAINT `certificate_id` FOREIGN KEY (`certificate_id`) REFERENCES `wp_cfs_certificates` (`certificate_id`) ON DELETE NO ACTION ON UPDATE CASCADE;
Its because mysql_query() doesn't support multiple queries
Its mentioned in the official PHP documentation
mysql_query() sends a unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specified link_identifier.
I am trying to install opencart-1.5.5.1 on my localhost. But i am getting an error after STEP3-CONFIGURATION. The error is
Notice: Error: 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 '\'0\', zone_id int(11) NOT NULL DEFAULT \'0\', PRIMARY KEY
(address_id' at line 13 Error No: 1064
CREATE TABLE `oc_address` ( `address_id` int(11) NOT NULL AUTO_INCREMENT, `customer_id` int(11) NOT NULL, `firstname` varchar(32) NOT NULL, `lastname` varchar(32) NOT NULL, `company` varchar(32) NOT NULL, `company_id` varchar(32) NOT NULL, `tax_id` varchar(32) NOT NULL, `address_1` varchar(128) NOT NULL, `address_2` varchar(128) NOT NULL, `city` varchar(128) NOT NULL, `postcode` varchar(10) NOT NULL, `country_id` int(11) NOT NULL DEFAULT \'0\', `zone_id` int(11) NOT NULL DEFAULT \'0\', PRIMARY KEY (`address_id`), KEY `customer_id` (`customer_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; in D:\wamp\www\vogue\system\database\mysql.php on line 50
Because probably You have magic_quotes_gpc directive turned On, thus all quotes and apostrophes gets escaped by auto adding of slashes...
In Your php.ini find the directive magic_quotes_gpc and set to Off.