$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
Akhmed
1,2194 gold badges24 silver badges52 bronze badges
1 Answer 1
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');
Sign up to request clarification or add additional context in comments.
4 Comments
DAB
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.
Amin
@DAB Is there any documentation for what you are saying? I'm asking because I want to figure out why it is like this.
DAB
@Amin - check out the answer here: stackoverflow.com/questions/6139597/…
SteveExdia
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.default