New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't rename a Column with MySQL #13012

Ark4ne opened this Issue Aug 9, 2017 · 3 comments


None yet
2 participants

Ark4ne commented Aug 9, 2017

Column renaming in MySQL dialect, wasn't implemented.

\Phalcon\Db\Dialect\Mysql::modifyColumn does not use the "currentColumn" variable, and therefore will never produce the column renaming request.

use \Phalcon\Db\Column;

$columnId = new Column('id', ['type' => Column::TYPE_INTEGER, 'primary' => true, 'autoIncrement' => true, 'unsigned' => true]);

$columnWrongName = new Column('wrong_name', ['type' => Column::TYPE_VARCHAR]);

$db = new \Phalcon\Db\Adapter\Pdo\Mysql([
    'host'     => 'localhost',
    'username' => 'root',
    'password' => '',
    'dbname'   => 'test',
    'charset'  => 'utf8',

$db->createTable('test', 'test', ['columns' => [$columnId, $columnWrongName]]);

$columnName = new Column('name', ['type' => Column::TYPE_VARCHAR]);

$db->modifyColumn('test', 'test', $columnName, $columnWrongName);

Output :

Fatal error: Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Champ 'name' inconnu dans test in {path}/test.php:23
Stack trace:
#0 [internal function]: PDO->exec('ALTER TABLE `te...')
#1 [internal function]: Phalcon\Db\Adapter\Pdo->execute('ALTER TABLE `te...')
#2 {path}/test.php(23): Phalcon\Db\Adapter->modifyColumn('test', 'test', Object(Phalcon\Db\Column), Object(Phalcon\Db\Column))
#3 {main}


  • Phalcon version: 3.x
  • PHP Version: 5.x / 7.x
  • Operating System:
  • Zephir version (if any):
  • Server:
  • Other related info (Database, table schema): MySQL

This comment has been minimized.


sergeyklay commented Nov 20, 2017

Could you please provide the latest stable version of Phalcon you are use? Also I'll need RDBMS version/name. This is why we created an issue template.


This comment has been minimized.

Ark4ne commented Nov 22, 2017


I tested with the last 3 stable version 3.0.4, 3.1.1, 3.2.4. and also with branch 3.3.x.
The problem is present on all.

For Mysql, I tested on 5.5, 5.6, 5.7.

This is because the "currentColumn" variable is not used:

For Postgresql, this variable is well used, which makes it possible to modify the columns.

use \Phalcon\Db\Column;
use \Phalcon\Db\Adapter\Pdo\Mysql as DbMysql;

$db = new DbMysql([
  'host'     => 'localhost',
  'username' => 'root',
  'password' => '',
  'dbname'   => 'schema_test',
  'charset'  => 'utf8',

$db->createTable('test', 'schema_test', [
  'columns' => [
    new Column('id', ['type' => Column::TYPE_INTEGER, 'primary' => true, 'autoIncrement' => true, 'unsigned' => true]),
    new Column('wrong_name', ['type' => Column::TYPE_VARCHAR, 'size' => 256]),

$currentColumnWrongName = new Column('wrong_name', ['type' => Column::TYPE_VARCHAR]);

$columnGoodName = new Column('name', ['type' => Column::TYPE_VARCHAR]);

$db->modifyColumn('test', 'schema_test', $columnGoodName, $currentColumnWrongName );

This comment has been minimized.


sergeyklay commented Jan 21, 2018

Fixed in the 3.3.x branch. Feel free to open a new issue if the problem appears again. Thank you for contributing.

@sergeyklay sergeyklay closed this Jan 21, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment