Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Auto increment not being set with migration
  • Not sure if this is just a issue with my setup but but Ids in my database are being set to auto increment. Migration file:
    public function up()
     {
      \DBUtil::create_table('issues', array(
       'id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true),
       'id' => array('constraint' => 11, 'type' => 'int'),
       'uid' => array('constraint' => 11, 'type' => 'int'),
       'issue' => array('type' => 'text'),
       'solution' => array('type' => 'text'),
       'thumbup' => array('constraint' => 11, 'type' => 'int'),
       'thumbdown' => array('constraint' => 11, 'type' => 'int'),
       'voters' => array('type' => 'text'),
       'published' => array('type' => 'boolean'),
       'latlng' => array('type' => 'text'),
       'category' => array('constraint' => 11, 'type' => 'int'),
       'resolved' => array('type' => 'boolean'),
       'created_at' => array('constraint' => 11, 'type' => 'int'),
       'updated_at' => array('constraint' => 11, 'type' => 'int'),
      ), array('id'));
     }
    

    Also originally I used camelcase for some of the field names. IE thumbUp while this was input into the database correctly Fuel was unable to duplicate that same naming conventions ******************
    edit
    ******************
    after posting I saw that 'id' was duplicated. so i commented out the second id , dropped the existing tables and ran migration again. This fixed the error. Updated code below
    public function up()
     {
      \DBUtil::create_table('issues', array(
       'id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true),
      // 'id' => array('constraint' => 11, 'type' => 'int'),
       'uid' => array('constraint' => 11, 'type' => 'int'),
       'issue' => array('type' => 'text'),
       'solution' => array('type' => 'text'),
       'thumbup' => array('constraint' => 11, 'type' => 'int'),
       'thumbdown' => array('constraint' => 11, 'type' => 'int'),
       'voters' => array('type' => 'text'),
       'published' => array('type' => 'boolean'),
       'latlng' => array('type' => 'text'),
       'category' => array('constraint' => 11, 'type' => 'int'),
       'resolved' => array('type' => 'boolean'),
       'created_at' => array('constraint' => 11, 'type' => 'int'),
       'updated_at' => array('constraint' => 11, 'type' => 'int'),
      ), array('id'));
     }
    
  • i was able to duplicate this on another machine. can someone else please confirm this as a bug?
  • It seems you may be adding the 'id' field explicitly in your command, like this:
    liquidfire$ php oil g model id:int[11] issue:text solution:text
    

    This will cause the problem you describe, because the 'id' field is automatically created in the migration anyway - like the 'created_at' and 'updated_at' fields. Oil would be, therefore, creating the 'id' field twice: once for you - because you requested it explicitly - and another time because it does it automatically anyway. If this is the problem, all you need to do is not declare the 'id' field in your command:
    liquidfire$ php oil g model issue:text solution:text
    
  • Ah this would explain it. I didn't know it was added automatically I knew the created_at field was there. thanks for explaining this.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion