Laravel change migration order

Roll back all the migrations (or start with a fresh database); Change the dates that form the first part of the migration filenames so they’re in the order you want (eg. for 2014_06_24_134109_update_database.php, the date & time is 2014-06-24, 13:41:09); Run the migrations again. With respect to your comment about foreign keys… I’m not sure … Read more

How to migrate a PostgreSQL database into a SQLServer one?

You should be able to find some useful information in the accepted answer in this Serverfault page: https://serverfault.com/questions/65407/best-tool-to-migrate-a-postgresql-database-to-ms-sql-2005. If you can get the schema converted without the data, you may be able to shorten the steps for the data by using this command: pg_dump –data-only –column-inserts your_db_name > data_load_script.sql This load will be quite slow, … Read more

Django migration error :you cannot alter to or from M2M fields, or add or remove through= on M2M fields

I stumbled upon this and although I didn’t care about my data much, I still didn’t want to delete the whole DB. So I opened the migration file and changed the AlterField() command to a RemoveField() and an AddField() command that worked well. I lost my data on the specific field, but nothing else. I.e. … Read more

Rails migration for has_and_belongs_to_many join table

Where: class Teacher < ActiveRecord::Base has_and_belongs_to_many :students end and class Student < ActiveRecord::Base has_and_belongs_to_many :teachers end for rails 4: rails generate migration CreateJoinTableStudentTeacher student teacher for rails 3: rails generate migration students_teachers student_id:integer teacher_id:integer for rails < 3 script/generate migration students_teachers student_id:integer teacher_id:integer (note the table name lists both join tables in alphabetical order) and … Read more

How do I handle too long index names in a Ruby on Rails ActiveRecord migration?

Provide the :name option to add_index, e.g.: add_index :studies, [“user_id”, “university_id”, “subject_name_id”, “subject_type_id”], unique: true, name: ‘my_index’ If using the :index option on references in a create_table block, it takes the same options hash as add_index as its value: t.references :long_name, index: { name: :my_index }