6
$table = $schema->getTable('agent_documents');
$table->addColumn('name_r', 'string');

How to add this field not as last one, but after another one?

asked Jan 19, 2016 at 9:43

1 Answer 1

9

Doctrine2 does not support adding column in other places than at the end. If you use ORM you shouldn't care about columns order. Nevertheless you could try to run instead SQL query (example for MySQL) like this:

$this->addSql('ALTER TABLE agent_documents ADD name_r VARCHAR(255) NOT NULL AFTER desired_column_name');
answered Jan 19, 2016 at 14:11
Sign up to request clarification or add additional context in comments.

4 Comments

Actually column order does matter. If you have a varchar that changes frequently, it should always go at the end. Otherwise, changing the contents of a varchar can result in a rewrite of the entire row.
@DAB Is there any documentation for what you are saying? I'm asking because I want to figure out why it is like this.
@Amin - check out the answer here: stackoverflow.com/questions/6139597/…
Doctrine follows defined column order when creating the table, right? So it's not ignoring it there, is it? Or does it add initially columns in random order, so that your id column is somewhere in the middle, and the rest are just random? If it's going to follow an order initially, why not always follow that defined order? It makes no sense.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.