I am attempting to create a Migration, adding a column to an existing table.
The up() method doing the initial create for the table looks like this:
public function up()
{
Schema::create('lead_assignments', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->increments('id');
$table->string('version');
$table->integer('reactor_track_id')->unsigned();
$table->integer('lead_id')->unsigned();
$table->integer('agent_id')->unsigned();
$table->integer('lead_stage_id')->unsigned();
$table->integer('managed_by_id')->unsigned();
$table->integer('side_of_deal_id')->unsigned();
$table->integer('coordinator_id')->unsigned();
$table->decimal('referral_fee', 15, 2);
$table->timestamp('response_ts');
$table->timestamps();
$table->softDeletes();
$table->foreign('lead_id')->references('id')->on('leads');
$table->foreign('agent_id')->references('id')->on('agents');
$table->foreign('lead_stage_id')->references('id')->on('lead_stages');
$table->foreign('managed_by_id')->references('id')->on('managed_bys');
$table->foreign('side_of_deal_id')->references('id')->on('side_of_deal');
$table->foreign('coordinator_id')->references('id')->on('users');
});
}
My Alter up() method looks like this:
public function up()
{
Schema::table('lead_assignments', function (Blueprint $table) {
if (!Schema::hasColumn('lead_assignments', 'property_type_id')) {
$table->integer('property_type_id')->unsigned();
$table->foreign('property_type_id')
->references('id')
->on('property_types');
}
if (!Schema::hasColumn('lead_assignments', 'referral_fee_expiration')) {
$table->date('referral_fee_expiration')->nullable();
}
$table->dropForeign('lead_assignments_side_of_deal_id_foreign');
});
Schema::table('lead_assignments', function (Blueprint $table) {
$table->integer('side_of_deal_id')->nullable()->change();
});
}
Here, I am trying to add the property_types column, checking to see if it exists first, and then making it a foreign key after creation. That works fine. Then I check to see if the referral_fee_expiration column is there, if not, I attempt to create it.
When doing the initial Migration after running 'migrate install', I get this MySQL Error:
[PDOException]
SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'referral_fee_expiration'
There are no other alters for this table, I'm not sure why it is complaining about the column already being there, when there are no migrations putting it there besides this one, and I'm checking to see if it exists before creation.
Any Advice?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire