This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
sokser+deatr10685
Let's say I have a basic model, but I want to add additional fields without deleting the current data. How can I go about doing this? It seems that whenever I update my models, the whole table is being deleted and then re-generated. As a sample, let's say below is by create_tablename.php file:
class CreateTypesMappingsTable extends Migration
{
public function up()
{
Schema::create('name_tablename', function($table)
{
//Settings
$table->engine = 'InnoDB';
//Fields
$table->increments('id');
$table->timestamps();
$table->integer('region_id')->nullable()->default(null);
$table->integer('country_id')->nullable()->default(null);
$table->integer('city_id')->nullable()->default(null);
$table->integer('type_id')->unsigned();
//Foreign keys
if(Schema::hasTable('name_tablename2'))$table->foreign('region_id')->references('id')->on('name_tablename2')->onDelete('cascade');
if(Schema::hasTable('name_tablename3'))$table->foreign('city_id')->references('id')->on('name_tablename3')->onDelete('cascade');
if(Schema::hasTable('name_tablename4'))$table->foreign('type_id')->references('id')->on('name_tablename4')->onDelete('cascade');
//Indexes
$table->index('region_id');
$table->index('city_id');
$table->index('type_id');
});
}
public function down()
{
Schema::dropIfExists('name_tablename');
}
}
Last updated
Fibonacci
you can remove the down method and create the following code (in new file) for example,
<?php namespace Rahman\Galleries\Updates;
use Schema;
use October\Rain\Database\Updates\Migration;
class AddIsPublishedToPetfies extends Migration
{
public function up()
{
if ( ! Schema::hasColumn('rahman_galleries_petfies', 'is_published'))
{
Schema::table('rahman_galleries_petfies', function($table)
{
$table->boolean('is_published')->after('id')->default(0);
});
}
}
public function down()
{
if (Schema::hasColumn('rahman_galleries_petfies', 'is_published'))
{
Schema::table('rahman_galleries_petfies', function($table)
{
$table->dropColumn('is_published');
});
}
}
}
update your YAML file and run this code,
php artisan october:up
Last updated
1-2 of 2