Skip to content
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

default value not being set up #429

Closed
stefanchiriac opened this issue Jun 14, 2015 · 15 comments
Closed

default value not being set up #429

stefanchiriac opened this issue Jun 14, 2015 · 15 comments

Comments

@stefanchiriac
Copy link
Contributor

Hello,

If I set a default value doesn't seems to be considered when I run the migration

new Column('status', [
    'type'    => Column::TYPE_INTEGER,
    'notNull' => true,
    'size'    => 1,
    'default' => 0,
    'after'   => 'role_id'
]);

There are any plans to add support for bigint, tinyint, timestamp?

Thanks

@mattvb91
Copy link
Contributor

I have just recently added pull request to the main phalcon repo because I needed to support blob types.

When I get time I will push bigint,tinyint and timestamp too. Hopefully they will make it into the 2.0.4 release.

@stefanchiriac
Copy link
Contributor Author

@mattvb91 That sounds nice. Do you have problems with default value not being set up or is just me?

@mattvb91
Copy link
Contributor

I seem to be having the same issue as you. Running v2.0.3 of the devtools.

I will look into this the same time as adding support for the new datatypes. I will update this issue if I have a branch you can test on.

@stefanchiriac
Copy link
Contributor Author

any news about this issue?

@sergeyklay
Copy link
Member

@stefanchiriac Curently we can use only Column::TYPE_BIGINTEGER because tinyint and timestamp isn't supported by Phalcon.

Can you explain please about "default values" related issue?

@stefanchiriac
Copy link
Contributor Author

The problem is with mysql/mariadb when you have a default value on a column.

  • if you generate a migration from a table, all default values are ignored and don't appear in your migration code.
  • if you run a migration, the column default value is ignored and is not set in db. For running a migration and missing types a work around is defining everything on type
new Column('created_at', [
    'type' => "TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP",
]);

@sergeyklay sergeyklay self-assigned this Aug 20, 2015
@sergeyklay
Copy link
Member

@stefanchiriac
I've tried to fix this behaviour. Can you please check it now in 2.0.x branch? But note currently Phalcon does not support Columt::TYPE_TIMESTAMP

sergeyklay added a commit that referenced this issue Aug 24, 2015
@stefanchiriac
Copy link
Contributor Author

now seems to work to generate and apply a migration with default value, except when 'default' => 0. In this case the value is being ignored

@sergeyklay
Copy link
Member

I'll try to deal with it

sergeyklay added a commit that referenced this issue Aug 26, 2015
@sergeyklay
Copy link
Member

@stefanchiriac I've tried to fix "default value" related issue. Can you please check it now in 2.0.x branch?

@stefanchiriac
Copy link
Contributor Author

I did some debugging myself and seems like the problem comes from the framework.
I ran directly modifyColumn and createTable functions and no luck

self::$_connection->modifyColumn($tableName, $tableColumn->getSchemaName(), $tableColumn);
self::$_connection->createTable($tableName, $defaultSchema, $definition);

@sergeyklay
Copy link
Member

@stefanchiriac I've fixed default value in Phalcon (2.0.x branch) phalcon/cphalcon#10849. Can you please build Phalcon from 2.0.x branch and check now?

@sergeyklay
Copy link
Member

@stefanchiriac You can try now with Phalcon 2.0.x

new Column('created_at', [
    'type'    => Column::TYPE_TIMESTAMP,
    'notNull' => true,
    'default' => 'CURRENT_TIMESTAMP'
]);

@stefanchiriac
Copy link
Contributor Author

all works fine now. Thanks

@sergeyklay
Copy link
Member

👍

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

No branches or pull requests

3 participants