SQLSTATE[42000]: Syntax error or access violation: 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_value VARCHAR(255), is_encrypted TINYINT(1) NOT NULL, is_met'
at line 1.
Failing Query:
"CREATE TABLE ohrm_display_field (report_group_id BIGINT NOT NULL,
name VARCHAR(255) NOT NULL, label VARCHAR(255) NOT NULL, field_alias
VARCHAR(255), is_sortable VARCHAR(10) NOT NULL, sort_order
VARCHAR(255), sort_field VARCHAR(255), element_type VARCHAR(255) NOT
NULL, element_property TEXT NOT NULL, width VARCHAR(255) NOT NULL,
is_exportable VARCHAR(10), text_alignment_style VARCHAR(20),
is_value_list TINYINT(1) NOT NULL, display_field_group_id 1 NOT NULL,
default_value VARCHAR(255), is_encrypted TINYINT(1) NOT NULL, is_meta
TINYINT(1) DEFAULT '0' NOT NULL, display_field_id BIGINT
AUTO_INCREMENT, PRIMARY KEY(display_field_id)) ENGINE = INNODB"
[Solved]
Next Error:
SQLSTATE[42000]: Syntax error or access violation: 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 ' PRIMARY
KEY(id)) ENGINE = INNODB' at line 1.
Failing Query:
"CREATE TABLE ohrm_job_interview_attachment (id BIGINT, interview_id BIGINT, file_name VARCHAR(255), file_type VARCHAR(255), file_size BIGINT, file_content LONGBLOB, attachment_type INT, comment , PRIMARY KEY(id)) ENGINE = INNODB"
Can anyone suggest what's the error in the indicated query?
Any effective guidance will be highly appreciated.
The issue is here
display_field_group_id 1 NOT NULL,
You need to assign some data type if its tinyint then the following should work
CREATE TABLE ohrm_display_field
(
report_group_id BIGINT NOT NULL,
name VARCHAR(255) NOT NULL,
label VARCHAR(255) NOT NULL,
field_alias VARCHAR(255),
is_sortable VARCHAR(10) NOT NULL,
sort_order VARCHAR(255),
sort_field VARCHAR(255),
element_type VARCHAR(255) NOT NULL,
element_property TEXT NOT NULL,
width VARCHAR(255) NOT NULL,
is_exportable VARCHAR(10),
text_alignment_style VARCHAR(20),
is_value_list TINYINT(1) NOT NULL,
display_field_group_id TINYINT(1) NOT NULL,
default_value VARCHAR(255),
is_encrypted TINYINT(1) NOT NULL,
is_meta TINYINT(1) DEFAULT '0' NOT NULL,
display_field_id BIGINT AUTO_INCREMENT,
PRIMARY KEY(display_field_id)
) ENGINE = INNODB
Related
I am trying to create a table for a blog and I am attempting to store 2 pictures in it so I resorted to storing it with a LONGBLOB (even though I know that everyone recommends storing it to the filesystem and then adding a link to it in the database but the thing is that there will be only one user and that will be me so there is no reason to overcomplicate it because this will not be a large amount of data or big pictures). Here is the database:
CREATE TABLE posts{
id BIGINT(10) NOT NULL AUTO_INCREMENT,
title VARCHAR(10) NOT NULL,
description VARCHAR(30) NOT NULL,
content VARCHAR(MAX) NOT NULL,
picOne LONGBLOB(MAX) NOT NULL,
picTwo LONGBLOB(MAX) NOT NULL,
PRIMARY KEY(id)
);
The error I get is
ERROR 1064 (42000): 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 'MAX) NOT NULL PRIMARY KEY (id) )' at line 5
I think that I am using the word MAX wrong or maybe there is something wrong with my whole data type or perhaps there is a better approach to this.
I appreciate the help.
Its the inappropriate curly brace { that you are using. Use the following query -
CREATE TABLE posts(
id BIGINT(10) NOT NULL AUTO_INCREMENT,
title VARCHAR(10) NOT NULL,
description VARCHAR(30) NOT NULL,
content VARCHAR(MAX) NOT NULL,
picOne LONGBLOB(MAX) NOT NULL,
picTwo LONGBLOB(MAX) NOT NULL,
PRIMARY KEY(id)
);
Perhaps just a typo.
Look at this. These should be the same () when creating a new table.
'CREATE TABLE posts{'
);
CREATE TABLE posts(
id BIGINT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(10) NOT NULL,
description VARCHAR(30) NOT NULL,
content VARCHAR(MAX) NOT NULL,
picOne LONGBLOB(MAX) NOT NULL,
picTwo LONGBLOB(MAX) NOT NULL
);
I replaced VARCHAR(MAX) to TEXT and LONGBLOB(MAX) to LONGBLOB. You can try this:
CREATE TABLE posts(
id BIGINT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(10) NOT NULL,
description VARCHAR(30) NOT NULL,
content TEXT NOT NULL,
picOne LONGBLOB NOT NULL,
picTwo LONGBLOB NOT NULL
);
What I ended up doing was change the VARCHAR value to something really high like VARCHAR(10000) and then leave the LONGBLOB to stand on its own and it worked perfectly. Here is what the code looks like:
CREATE TABLE pages(
id BIGINT(10) NOT NULL AUTO_INCREMENT,
title VARCHAR(10) NOT NULL,
description VARCHAR(30) NOT NULL,
content VARCHAR(10000) NOT NULL,
picOne LONGBLOB NOT NULL,
picTwo LONGBLOB NOT NULL,
PRIMARY KEY(id)
);
[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table def
inition; there can be only one auto column and it must be defined as a key
(SQL: create table `students` (`id` int unsigned not null auto_increment pr
imary key, `student_id` int unsigned not null auto_increment primary key, `
stuent_name` varchar(50) not null, `student_email` varchar(50) not null, `s
tudent_username` varchar(50) not null, `student_phone` varchar(50) not null
, `student_photo` text not null, `student_sex` varchar(191) not null, `stud
ent_status` varchar(191) not null, `created_at` timestamp null, `updated_at
` timestamp null) default character set utf8mb4 collate utf8mb4_unicode_ci)
i dont know what happen , this problem is happen when i try to migrate
You have two auto_increment key id and studuent_id. You can only set one as the auto increment key.
I created a migration:
public function up()
{
Schema::create('accounts', function(Blueprint $table) {
$table->increments('id')->primary()->nullable(false)->index();
$table->string('username', 32)->nullable(false)->index();
$table->string('sha_pass_hash', 40)->nullable(false);
$table->string('sessionkey', 80)->nullable(false);
$table->string('v', 64)->nullable(false);
$table->string('s', 64)->nullable(false);
$table->string('token_key', 100)->nullable(false);
$table->string('email', 255)->nullable(false)->unique();
$table->timestamp('joindate')->nullable(false)->useCurrent();
$table->string('last_ip', 15)->nullable(false)->default('127.0.0.1');
$table->string('last_attempt_ip', 15)->nullable(false)->default('127.0.0.1');
$table->unsignedInteger('failed_logins', 10)->nullable(false)->default(0);
$table->unsignedTinyInteger('locked', 3)->nullable(false)->default(0);
$table->timestamp('last_login')->nullable(false)->default('0000-00-00 00:00:00');
$table->tinyInteger('online', 3)->nullable(false)->default(0);
$table->unsignedTinyInteger('expansion', 3)->nullable(false)->default(6);
$table->bigInteger('mutetime', 20)->nullable(false);
$table->string('mutereason', 255)->nullable(false);
$table->string('muteby', 50)->nullable(false);
$table->unsignedTinyInteger('locale', 50)->nullable(false);
$table->string('os', 3)->nullable(false);
$table->unsignedInteger('recruiter', 10)->nullable(false);
$table->unsignedInteger('battlenet_account', 10)->nullable(true)->default(NULL);
$table->tinyInteger('battlenet_index', 3)->nullable(true)->default(NULL);
});
}
And when i'm trying to executed command
php artisan migrate
I'm getting error:
[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'failed_logins' (SQL: create table `accounts` (`id` int unsigned
not null auto_increment primary key, `username` varchar(32) not null, `sha_pass_hash` varchar(40) not null, `sessionkey` varchar(80) not null, `v`
varchar(64) not null, `s` varchar(64) not null, `token_key` varchar(100) not null, `email` varchar(255) not null, `joindate` timestamp default CURR
ENT_TIMESTAMP not null, `last_ip` varchar(15) not null default '127.0.0.1', `last_attempt_ip` varchar(15) not null default '127.0.0.1', `failed_log
ins` int unsigned not null default '0' auto_increment primary key, `locked` tinyint unsigned not null default '0' auto_increment primary key, `last
_login` timestamp not null default '0000-00-00 00:00:00', `online` tinyint not null default '0' auto_increment primary key, `expansion` tinyint uns
igned not null default '6' auto_increment primary key, `mutetime` bigint not null auto_increment primary key, `mutereason` varchar(255) not null, `
muteby` varchar(50) not null, `locale` tinyint unsigned not null auto_increment primary key, `os` varchar(3) not null, `recruiter` int unsigned not
null auto_increment primary key, `battlenet_account` int unsigned null auto_increment primary key, `battlenet_index` tinyint null auto_increment p
rimary key) default character set utf8 collate utf8_unicode_ci)
[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'failed_logins'
What i noticed is that every integer type gets auto_increment primary key in sql query. I think it could be the problem, as far as know that auto increment columns can't have default values.
If you take a look at the source code for the unsignedInteger method, you'll notice the second parameter doesn't specify length, but rather is for an autoIncrement boolean. You'll need to update your various integer methods accordingly.
I am creating a dynamic table using mysql query table name should be unique that's why i have added user id to table name.
In Controller:
$last_id = $this->User->getLastInsertID();
//$table_name = 'hello_'.$last_id.'_tutors';
// debug($table_name);
$this->User->query("CREATE TABLE IF NOT EXISTS `post_`.$last_id.`_tutors` (
`id` int(8) NOT NULL AUTO_INCREMENT,
`user_id` int(8) NOT NULL,
`tutor_name` varchar(50) NOT NULL,
`tutor_email` varchar(50) NOT NULL,
`tutor_number` varchar(50) NOT NULL,
`tutor_gender` varchar(50) NOT NULL,
`tutor_address` varchar(100) NOT NULL,
`city_id` int(11) NOT NULL,
`area_id` int(11) NOT NULL,
`matric` varchar(200) NOT NULL,
`inter` varchar(200) NOT NULL,
`graduation` varchar(200) NOT NULL,
`masters` varchar(200) NOT NULL,
`diploma` varchar(200) NOT NULL,
`other_education` varchar(200) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=67 ;
");
it gave syntax error like:
Syntax error or access violation: 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 '.75._tutors ( tutor_name
varchar(50) NOT NULL, tutor_email var' at line 1
if anyone may help. Thanks in advance.
Try using
$this->User->query("CREATE TABLE IF NOT EXISTS `post_".$last_id."_tutors` (
I am trying to run this query in my database:
CREATE TABLE users(
user_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
username VARCHAR NOT NULL,
userpass VARCHAR NOT NULL,
first_name VARCHAR NOT NULL,
last_name VARCHAR NOT NULL,
email VARCHAR NOT NULL,
address VARCHAR NOT NULL,
phone BIGINT UNSIGNED NOT NULL,
PRIMARY KEY(user_id)
)
MySQL returns this error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NOT NULL,
userpass VARCHAR NOT NULL,
first_name VARCHAR NOT NULL,
' at line 3
I cant figure out what is wrong with the code...
You need to specify size for VARCHAR columns:
CREATE TABLE users( user_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
username VARCHAR(100) NOT NULL,
userpass VARCHAR(100) NOT NULL,
first_name VARCHAR(100) NOT NULL,
last_name VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL,
address VARCHAR(100) NOT NULL,
phone BIGINT UNSIGNED NOT NULL,
PRIMARY KEY(user_id) );
SqlFiddleDemo
Storing phone number as BIGINT is not best idea. Consider normal string instead.