Questions tagged [migration]

An action of moving between major versions of any framework, product or language, or, just as commonly, alteration to the data schema of an application. This might involve modifying existing data to make it work with the new version.

An action of moving between major versions of any framework, product or language, or, just as commonly, alteration to the data schema of an application. This might involve modifying existing data to make it work with the new version.

11009 questions
230
votes
8 answers

How to change a nullable column to not nullable in a Rails migration?

I created a date column in a previous migration and set it to be nullable. Now I want to change it to be not nullable. How do I go about doing this assuming there are null rows in that database? I'm ok with setting those columns to Time.now if…
Kevin Pang
  • 41,172
  • 38
  • 121
  • 173
220
votes
3 answers

Backwards migration with Django South

Ok, so this seems like a really silly thing to ask, and I'm sure I'm missing something somewhere. How do you perform a backwards migration using South on Django? So I've tweaked my models, created a migration with schemamigration, run the migration…
Ruiwen
  • 2,325
  • 2
  • 16
  • 12
210
votes
21 answers

List all sequences in a Postgres db 8.1 with SQL

I'm converting a db from postgres to mysql. Since i cannot find a tool that does the trick itself, i'm going to convert all postgres sequences to autoincrement ids in mysql with autoincrement value. So, how can i list all sequences in a Postgres DB…
apelliciari
  • 8,241
  • 9
  • 57
  • 92
189
votes
9 answers

rake db:schema:load vs. migrations

Very simple question here - if migrations can get slow and cumbersome as an app gets more complex and if we have the much cleaner rake db:schema:load to call instead, why do migrations exist at all? If the answer to the above is that migrations are…
sscirrus
  • 55,407
  • 41
  • 135
  • 228
187
votes
40 answers

Laravel migration: unique key is too long, even if specified

I am trying to migrate a users table in Laravel. When I run my migration I get this error: [Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes…
harryg
  • 23,311
  • 45
  • 125
  • 198
170
votes
17 answers

How to implement LIMIT with SQL Server?

I have this query with MySQL: select * from table1 LIMIT 10,20 How can I do this with SQL Server?
Bigballs
  • 3,729
  • 10
  • 30
  • 27
167
votes
9 answers

Populating a database in a Laravel migration file

I'm just learning Laravel, and have a working migration file creating a users table. I am trying to populate a user record as part of the migration: public function up() { Schema::create('users', function($table){ …
Adam Hopkinson
  • 28,281
  • 7
  • 65
  • 99
165
votes
7 answers

Adding :default => true to boolean in existing Rails column

I've seen a few questions (namely this one) here on SO about adding a default boolean value to an existing column. So I tried the change_column suggestion but I mustn't be doing it right. I tried: $ change_column :profiles, :show_attribute,…
tvalent2
  • 4,959
  • 10
  • 45
  • 87
162
votes
10 answers

Rails 3 migrations: Adding reference column?

If I create a new rails 3 migration with (for example) rails g migration tester title:tester user:references , everything works fine...however if I add a column with something along the lines of: rails g migration add_user_to_tester…
PlankTon
  • 12,443
  • 16
  • 84
  • 153
156
votes
17 answers

Dependency graph of Visual Studio projects

I'm currently migrating a big solution (~70 projects) from VS 2005 + .NET 2.0 to VS 2008 + .NET 3.5. Currently I have VS 2008 + .NET 2.0. The problem is that I need to move projects one by one to new .NET framework ensuring that no .NET 2.0 project…
Migol
  • 8,161
  • 8
  • 47
  • 69
156
votes
5 answers

Rails migration: t.references with alternative name?

So I have a create_table like this for Courses at a School: create_table :courses do |t| t.string :name t.references :course t.timestamps end but I want it to reference two other courses like: has_many :transferrable_as # A Course has_many…
themirror
  • 9,963
  • 7
  • 46
  • 79
153
votes
6 answers

Rails: Adding an index after adding column

Suppose I created a table table in a Rails app. Some time later, I add a column running: rails generate migration AddUser_idColumnToTable user_id:string. Then I realize I need to add user_id as an index. I know about the add_index method, but…
user1611830
  • 4,749
  • 10
  • 52
  • 89
150
votes
27 answers

Laravel Migrate Specific File(s) from Migrations

Hi read all the included documentation here in https://laravel.com/docs/5.4/migrations. Is there a way on how to migrate a certain migration file (1 migration only), cause right now every time there is a change I use php artisan migrate:refresh and…
Martney Acha
  • 2,802
  • 4
  • 33
  • 48
148
votes
5 answers

Ruby on Rails: How do I add a not null constraint to an existing column using a migration?

In my Rails (3.2) app, I have a bunch of tables in my database but I forgot to add a few not null constraints. How can I write a migration which adds not null to an existing column?
David Robertson
  • 1,809
  • 3
  • 12
  • 12
142
votes
10 answers

How can I rename column in laravel using migration?

I have columns as mentioned bellow: public function up() { Schema::create('stnk', function(Blueprint $table) { $table->increments('id'); $table->string('no_reg', 50)->unique(); $table->string('no_bpkb',…
Ariasa
  • 1,709
  • 3
  • 13
  • 18