Can i use mysql varchar as primary key in fuel cms

edited January 2019 in Modules

hi, all,
i recently start to use fuel cms. in my requirement need a string as table primary key. like guid etc. when i develop the code, i found like the key value is 123a, list page no problem, edit page is ok too. but when i save the data, the key value will become to 123. anybody can tell me what happened. the cms can't use string as a primary key or need some config?



  • Tough to say what may be happening but it looks like it's trying to cast the ID value to be and int. A simple way to debug could be to use one of the model hook methods like "on_before_validate" or "on_before_save" to see if the value that is being prepped for save at those stages is correct:

    public function on_before_validate($values)
        $values = parent::on_before_save($values);
        print_r($values); exit();
        return $values;

    Another option would be to have that key just be a unique indexed field on the table and you can specify in the model that column as a unique field to add validation for that.

  • Thanks for your reply admin! one thing need to confirm . in cms varchar as primary key is allow right? the cms have no limint about this?

  • edited January 2019

    Problem have been solved. add this codes to model config

    public $key_field = table primary key
    public $has_auto_increment = FALSE;
    public $hidden_fields = array('table primary key');

    then everything will be ok!


Sign In or Register to comment.