anand-patel / oc-seo-extension

SEO Extension for October CMS Pages
12 stars 29 forks source link

Can not reinstall the plugin if missing columns with a prefix seo_ #8

Open iammartinbelobrad opened 9 years ago

iammartinbelobrad commented 9 years ago

eg.:

[Illuminate\Database\QueryException]                                                                                 
  SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'seo_title'; check that column/key exists (SQL:   
  alter table `rainlab_blog_posts` drop `seo_title`)
tonyputi commented 6 years ago

Here the solution. You need to replace the migration file inside plugin with this!

<?php namespace AnandPatel\SeoExtension\Updates;

use Schema;
use October\Rain\Database\Updates\Migration;
use System\Classes\PluginManager;
class CreateBlogPostsTable extends Migration
{

    public function up()
    {
        if(PluginManager::instance()->hasPlugin('RainLab.Blog'))
        {
            Schema::table('rainlab_blog_posts', function($table)
            {
                $table->string('seo_title')->nullable();
                $table->string('seo_description')->nullable();
                $table->string('seo_keywords')->nullable();
                $table->string('canonical_url')->nullable();
                $table->string('redirect_url')->nullable();
                $table->string('robot_index')->nullable();
                $table->string('robot_follow')->nullable();
            });
        }
    }

    public function down()
    {
        if(PluginManager::instance()->hasPlugin('RainLab.Blog'))
        {
            Schema::table('rainlab_blog_posts', function($table)
            {
                $table->dropColumn(['seo_title', 'seo_description', 'seo_keywords', 'canonical_url', 'redirect_url', 'robot_index', 'robot_follow']);

            });
        }

    }

}