Why doesn't the follow SQL table creation work? - mysql

CREATE TABLE `auth_user` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`password` VARCHAR( 128 ) COLLATE utf8_bin NOT NULL ,
`last_login` DATETIME( 6 ) DEFAULT NULL ,
`is_superuser` TINYINT( 1 ) NOT NULL ,
`username` VARCHAR( 30 ) COLLATE utf8_bin NOT NULL ,
`first_name` VARCHAR( 30 ) COLLATE utf8_bin NOT NULL ,
`last_name` VARCHAR( 30 ) COLLATE utf8_bin NOT NULL ,
`email` VARCHAR( 254 ) COLLATE utf8_bin NOT NULL ,
`is_staff` TINYINT( 1 ) NOT NULL ,
`is_active` TINYINT( 1 ) NOT NULL ,
`date_joined` DATETIME( 6 ) NOT NULL ,
PRIMARY KEY ( `id` ) ,
UNIQUE KEY `username` ( `username` )
) ENGINE = INNODB AUTO_INCREMENT =2 DEFAULT CHARSET = utf8 COLLATE = utf8_bin;
*\#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 '(6) DEFAULT NULL,
`is_superuser` tinyint(1) NOT NULL,
`username` varchar(30)' at line 4***
This is the auth_user table from a django project. The SQL file was exported from my local MySQL database, but I can't import to the online mysql database. Could somebody can help me?

You do not need the length for datetime
`date_joined` DATETIME( 6 ) NOT NULL ,
should be
`date_joined` DATETIME NOT NULL ,
https://dev.mysql.com/doc/refman/5.0/en/datetime.html

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.

error upload .sql file of wordpress site

this is the 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 'AS ical subscribe access key,
created_on datetime DEFAULT NULL,
`updated' at line 20
Erreur
requĂȘte SQL:
-- --------------------------------------------------------
--
-- Structure de la table `pec_calendars`
--
CREATE TABLE `pec_calendars` (
`id` INT( 11 ) UNSIGNED NOT NULL ,
`type` ENUM( 'user', 'group', 'url' ) DEFAULT 'user',
`user_id` INT( 11 ) UNSIGNED DEFAULT NULL ,
`name` VARCHAR( 100 ) DEFAULT NULL ,
`description` TEXT,
`color` VARCHAR( 7 ) DEFAULT NULL ,
`admin_id` INT( 11 ) DEFAULT NULL ,
`status` ENUM( 'on', 'off' ) DEFAULT 'on',
`show_in_list` ENUM( '0', '1' ) DEFAULT NULL ,
`public` TINYINT( 3 ) UNSIGNED DEFAULT '0',
`reminder_message_email` TEXT,
`reminder_message_popup` TEXT,
`access_key` VARCHAR( 32 ) DEFAULT NULL COMMENT AS `ical subscribe access key` ,
`created_on` DATETIME DEFAULT NULL ,
`updated_on` DATETIME DEFAULT NULL
) ENGINE = INNODB DEFAULT CHARSET = utf8;
Guess your query should be:
CREATE TABLE pec_calendars
(
id INT(11) UNSIGNED NOT NULL,
type ENUM('user', 'group', 'url') DEFAULT 'user',
user_id INT(11) UNSIGNED DEFAULT NULL,
name VARCHAR(100) DEFAULT NULL,
description TEXT,
color VARCHAR(7) DEFAULT NULL,
admin_id INT(11) DEFAULT NULL,
status ENUM('on', 'off') DEFAULT 'on',
show_in_list ENUM('0', '1') DEFAULT NULL,
public TINYINT(3) UNSIGNED DEFAULT '0',
reminder_message_email TEXT,
reminder_message_popup TEXT,
access_key VARCHAR(32) DEFAULT NULL,
created_on DATETIME DEFAULT NULL,
updated_on DATETIME DEFAULT NULL
)
engine = innodb
DEFAULT charset = utf8;

mysql #1071 - Specified key was too long; max key length is 767 bytes

I am try to execute the below SQL and it is given the error above
CREATE TABLE IF NOT EXISTS `oic_assemblyman_data` (
`id` bigint( 100 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
`firstname` varchar( 300 ) COLLATE utf8_unicode_ci NOT NULL ,
`lastname` varchar( 300 ) COLLATE utf8_unicode_ci NOT NULL ,
`email` varchar( 300 ) COLLATE utf8_unicode_ci DEFAULT NULL ,
`phone` varchar( 300 ) COLLATE utf8_unicode_ci DEFAULT NULL ,
`office_latitude` varchar( 20 ) COLLATE utf8_unicode_ci DEFAULT NULL ,
`office_longitude` varchar( 20 ) COLLATE utf8_unicode_ci DEFAULT NULL ,
`website_welcome_address` text COLLATE utf8_unicode_ci,
`website_header_color` varchar( 15 ) COLLATE utf8_unicode_ci DEFAULT NULL ,
`website_footer_color` varchar( 20 ) COLLATE utf8_unicode_ci DEFAULT NULL ,
`about_yourself` text COLLATE utf8_unicode_ci NOT NULL ,
`password` varchar( 100 ) COLLATE utf8_unicode_ci NOT NULL ,
PRIMARY KEY ( `id` ) ,
UNIQUE KEY `email` ( `email` )
) ENGINE = InnoDB DEFAULT CHARSET = utf8 COLLATE = utf8_unicode_ci;
Could someone point out what is causing the problem
change your email to varchar(255) should works. i think it using utf-8 encoding which max 3 bytes per character, then 767/3=255...2
so you can set max length to 255

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

SQL syntax error

CREATE TABLE `users` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`type` ENUM( `member` , `admin` ) NOT NULL ,
`username` VARCHAR( 30 ) NOT NULL ,
`email` VARCHAR( 80 ) NOT NULL ,
`pass` VARBINARY( 32 ) NOT NULL ,
`first_name` VARCHAR( 20 ) NOT NULL ,
`last_name` VARCHAR( 40 ) NOT NULL ,
`date_expires` DATE NOT NULL ,
`date_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
`date_modified` TIMESTAMP NOT NULL DEFAULT `0000-00-00 00:00:00` ,
PRIMARY KEY ( `id` ) ,
UNIQUE KEY `username` ( `username` ) ,
UNIQUE KEY `email` ( `email` )
) ENGINE = MYISAM DEFAULT CHARSET = utf8;
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 'member,admin) NOT NULL, username VARCHAR(30) NOT NULL,
email VARCHAR(80)' at line 3
The shared server I am using, uses 4.4. Thanks for reading. I am an absolute novice, having only been learning php/mysql for one month, so please speak in layman's terms.
You need to quote ENUM values
type ENUM( 'member' , 'admin' ) NOT NULL ,
not backtick them as you do now
Same thing for this line
`date_modified` TIMESTAMP NOT NULL DEFAULT `0000-00-00 00:00:00`
should be
`date_modified` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00'
This page indicates that your ENUM values should be strings, so need to be surrounded by single quotes.
type ENUM( 'member' , 'admin' ) NOT NULL
okey fixed it here is it :)
CREATE TABLE `users` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
type ENUM( 'member' , 'admin' ) NOT NULL ,
`username` varchar(30) NOT NULL default '',
`password` varchar(255) NOT NULL default '',
`first_name` varchar (15) NOT NULL,
`last_name` varchar (30) NOT NULL,
`gender` ENUM('male', 'female') NOT NULL default 'male',
`email` varchar(50) NOT NULL default '',
`skype` varchar(50) NOT NULL default 'Not Specified',
`facebook` varchar(150) NOT NULL default 'Not Specified',
`location` varchar(100) NOT NULL default 'Not Specified',
PRIMARY KEY (`id`),
UNIQUE KEY (`email`),
KEY (`email`, `password`)
) ENGINE = MYISAM DEFAULT CHARSET = utf8;