Mysql, Issue with inserting a row into a table

Lucas Ou-Yang

I've inserted many rows into tables before in the past but this particular instance keeps giving me an error and I can't figure out why. I've restarted mysql/tried disabling foreign key checks and etc but it still fails.

Here is my insert command:

insert into subreddits_subreddit(name, desc, admin_id) values('firstSubreddit', 
      'This is a test.', 1)

My error:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that c   
orresponds to your MySQL server version for the right syntax to use near 'desc, admin_id) 
values('firstSubreddit', 'This is a test.', 1)' at line 1

Here is the schema for subreddits_subreddit.

subreddits_subreddit | CREATE TABLE `subreddits_subreddit` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) DEFAULT NULL,
  `desc` varchar(3000) DEFAULT NULL,
  `admin_id` int(11) DEFAULT NULL,
  `created_on` datetime DEFAULT NULL,
  `updated_on` datetime DEFAULT NULL,
  `status` smallint(6) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`),
  KEY `user_id` (`admin_id`),
  CONSTRAINT `subreddits_subreddit_ibfk_1` FOREIGN KEY (`admin_id`) REFERENCES 
          `users_user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |

Here is the users table which it references:

 users_user | CREATE TABLE `users_user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(80) DEFAULT NULL,
  `email` varchar(200) DEFAULT NULL,
  `password` varchar(200) DEFAULT NULL,
  `created_on` datetime DEFAULT NULL,
  `status` smallint(6) DEFAULT NULL,
  `role` smallint(6) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `username` (`username`),
  UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1 |

The users_user table has one row inside it with an id value of 1, so the user FK reference should be ok. The subreddits_subreddit table is empty (I just made it)

Any ideas on what to do? Thank you.

Jon B

desc is a keyword for use with order by and whatnot

Escape desc by putting backtick magic quotes:

insert into subreddits_subreddit(name, `desc`, admin_id)
  values('firstSubreddit', 'This is a test.', 1)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Mysql, Issue with inserting a row into a table

From Dev

Issue Inserting Row MySQL, no MySQL Error

From Dev

jQuery - issue inserting new row in html table

From Dev

MYSQL - Inserting multiple inputs into a table issue

From Dev

MySQL table - how to do the INSERTing fast on a billion row table?

From Dev

MySQL table - how to do the INSERTing fast on a billion row table?

From Dev

Inserting row into join table?

From Dev

Inserting row to temp table

From Dev

Inserting a row in a table with javascript

From Dev

Inserting Large Amounts of data into MySQL Table only inserts 1 row?

From Dev

Inserting a row in a mysql table. It doesn't work?

From Dev

C# to mysql - inserting new row to table with foreign key

From Dev

Inserting selected row into mysql

From Dev

Inserting selected row into mysql

From Dev

mysql - Inserting row in table 1 when specific row deleted on table 2

From Dev

Inserting SQL query table issue

From Dev

MySql inserting decimals into table

From Dev

PHP/MySQL issue inserting array

From Dev

PHP/MySQL issue inserting array

From Dev

Having an issue inserting more than 1 row from a CSV into mysql database

From Dev

Inserting new row into mysql database

From Dev

selectively UPDATING old rows when INSERTING new ones into table (trigger issue) in MySQL

From Dev

Table Row attr() Issue

From Dev

Exception while inserting mysql table

From Dev

Inserting JSON data into MySQL table

From Dev

inserting data into a mysql table dynamically

From Dev

Error inserting values to a table in MySql

From Dev

Exception while inserting mysql table

From Dev

Inserting into MySQL table using a variable

Related Related

HotTag

Archive