I need to add a new column in one of my tables, but this column in turn is a foreign key of another table but I don't know how to do it...
I tried this but obviously it gave me an error:
ALTER TABLE ordenes ADD COLUMN ticket varchar(50) FOREIGN KEY (ticket) REFERENCES tickets(ticket)
First add just the column and then the fk:
In the tickets table it would be better to call it "something" + id instead of "ticket". Remember that it has to be a unique field.
The syntax you are using is not supported by mysql. Add the column and constraint separately, this will work on most engines, not just MySQL:
I've added a name to the constraint, but you could skip that part.