1

Iam using this query to create tables in the Database:

$this->dbforge->add_field("label varchar(100) NOT NULL DEFAULT 'default label'");

How can I add Primary key, Unique key Full text and Index attributes to a Field?

1 Answer 1

2

You can add a Key with the add_key function:

$this->dbforge->add_key ( 'field_name', TRUE );

The second parameter indicates whether or not you want a Primary Key.

I haven't been able to find a way to add different types of keys using DBForge, short of extending the class. I have found it easier to run a mysql query that adds the index, once I'm sure the table has been created successfully.

$query = "ALTER TABLE `table_name` ADD UNIQUE INDEX `index_name` (`field_name`);";
$this->db->query ( $query );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.