I'm trying to create a table with Laravel migrations but I'm having some trouble. I just need to create a table with a primary pair ('user_id' and 'media_id'), being 'inc' an auto increment. I can do it in MySQL, but I can't manage to do it with Laravel Migrations since increments() also set the field as primary. error i get
SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key
thats i hae done so far
public function up()
{
Schema::create('tagtables', function (Blueprint $table) {
$table->integer('media_id');
$table->integer('user_id');
$table->boolean('approved')->default(false);
$table->increments('inc')->unsigned();
$table->timestamps();
$table->dropPrimary('tagtables_inc_primary');
$table->primary(array('user_id','media_id'));
// $table->foreign('media_id')->references('id')->on('media')->onUpdate('cascade')->onDelete('cascade');
// $table->foreign('user_id')->references('id')->on('users')->onUpdate('cascade')->onDelete('cascade');
});
// Schema::table('tagtables', function (Blueprint $table) {
// //$table->increments('id');
// $table->primary(array('user_id','media_id'));
// $table->foreign('media_id')->references('id')->on('media')->onUpdate('cascade')->onDelete('cascade');
// $table->foreign('user_id')->references('id')->on('users')->onUpdate('cascade')->onDelete('cascade');
// });
}
I think you need this:
and put this in the model: