Question

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
Was it helpful?

Solution

You made a typo:

`username` varhcar(50) NOT NULL,

should be:

`username` varchar(50) NOT NULL,
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top