Laravel-medialibrary: An error occurred with the name of the table medias' doesn't exist

Created on 10 May 2020  路  8Comments  路  Source: spatie/laravel-medialibrary

It has been working fine and the project has been working for a year, but upon updating composer
The following error occurred
Base table or view not found: 1146 Table 'medias' doesn't exist (SQL: select * from medias where medias.model_id in (1) and medias.model_type =
But its name is the table in the database "media" not "medias"
It has thousands of rows
What should I do to solve this problem?

Details of the current project:
laravel/framework v7.10.3
"spatie/laravel-medialibrary": "^7.0.0",

It was working properly to issue
laravel/framework v7.9.2

Most helpful comment

@AEK-BKF best solution is you can override model implementation here

then in your own model must be like this

<?php

namespace App\Models;

class Media extends \Spatie\MediaLibrary\Models\Media
{
    protected $table = 'media';
}

If this fix by library then you can n remove this model and revert changes in config

All 8 comments

Same here, I've just updated the composer, and got that error !!!

"laravel/framework": "^6.2",
"spatie/laravel-medialibrary": "^7.0.0",

same here
using PHP7.2

I fixed it by renaming the table media to medias in Database !

that's one of the solution, but this need to be done on library itself

this is occure when updating this

vagrant@homestead:~/code/project$ composer update
Loading composer repositories with package information                                                                                                Updating dependencies (including require-dev)         
Package operations: 0 installs, 7 updates, 0 removals
  - Updating doctrine/inflector (1.3.1 => 1.4.0): Loading from cache
  - Updating symfony/polyfill-php72 (v1.15.0 => v1.16.0): Loading from cache
  - Updating symfony/polyfill-mbstring (v1.15.0 => v1.16.0): Loading from cache
  - Updating symfony/polyfill-intl-idn (v1.15.0 => v1.16.0): Loading from cache
  - Updating symfony/polyfill-iconv (v1.15.0 => v1.16.0): Loading from cache
  - Updating symfony/polyfill-php73 (v1.15.0 => v1.16.0): Loading from cache
  - Updating symfony/polyfill-ctype (v1.15.0 => v1.16.0): Loading from cache
Writing lock file

@AEK-BKF best solution is you can override model implementation here

then in your own model must be like this

<?php

namespace App\Models;

class Media extends \Spatie\MediaLibrary\Models\Media
{
    protected $table = 'media';
}

If this fix by library then you can n remove this model and revert changes in config

this should be close

Was this page helpful?
0 / 5 - 0 ratings

Related issues

swash13 picture swash13  路  3Comments

drtheuns picture drtheuns  路  3Comments

aaronfullerton picture aaronfullerton  路  4Comments

mohammad6006 picture mohammad6006  路  4Comments

Nks picture Nks  路  3Comments