MySQL Error - SQLSTATE [42000]: Syntax error or access violation: 1064 [closed]

戏子无情 提交于 2019-12-14 03:05:44

问题


I've looked through the suggested code and cannot find an answer that fixes the problem so I am asking away.

I am using MAMP v2.0.5, MySQL v5.5.9, PHP v5.3.6 (according to MAMP, v5.3.8 according to OS X) and FuelPHP v1.1, and being new to frameworks I am working through a tutorial. Part of the tutorial requires the use of 'oil' to carry out migrations to update the project. Having defined a table, the migration applies the SQL to generate the table. When I do so, I get the above error. Having looked through the generated code I can't find any errors (maybe I am missing something obvious). I am using PDO and have also checked that my sql_mode = '', which it does. Running a MySQL query from the command line and phpMyAdmin confirms this. I think this is a MySQL error and not a problem with FuelPHP/oil. Does anybody have any suggestions?

The generated SQL:

CREATE TABLE IF NOT EXISTS `users` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `username` varhcar(50) NOT NULL,
    `password` varchar(255) NOT NULL,
    `group` int(11) NOT NULL,
    `email` varchar(255) NOT NULL,
    `last_login` int(11) NOT NULL,
    `login_hash` varchar(255) NOT NULL,
    `profile_fields` text NOT NULL,
    `created_at` int(11) NOT NULL,
    `updated_at` int(11) NOT NULL,
    PRIMARY KEY `id` (`id`)
) DEFAULT CHARACTER SET utf8;

The error:

    bash:blog me$ oil refine migrate
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 'varhcar(50) NOT NULL,
    `password` varchar(255) NOT NULL,
    `group` int(11) NOT NU' at line 3 with query: "CREATE TABLE IF NOT EXISTS `users` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `username` varhcar(50) NOT NULL,
    `password` varchar(255) NOT NULL,
    `group` int(11) NOT NULL,
    `email` varchar(255) NOT NULL,
    `last_login` int(11) NOT NULL,
    `login_hash` varchar(255) NOT NULL,
    `profile_fields` text NOT NULL,
    `created_at` int(11) NOT NULL,
    `updated_at` int(11) NOT NULL,
    PRIMARY KEY `id` (`id`)
) DEFAULT CHARACTER SET utf8;" in COREPATH/classes/database/pdo/connection.php on line 137

回答1:


You made a typo:

`username` varhcar(50) NOT NULL,

should be:

`username` varchar(50) NOT NULL,


来源:https://stackoverflow.com/questions/9474576/mysql-error-sqlstate-42000-syntax-error-or-access-violation-1064

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!