SQLSTATE[42P01]: Undefined table: 7 ERROR: relation

Asked

Viewed 1,268 times

-2

I have a project where I made some Migrations, but when I did I managed to run the Migrations quietly. I recently formatted my computer, installed Postgressql and did my "Restore" from my DB. In that I downloaded my project again and so I went to give php artisan migrate appeared the following error.

    In Connection.php line 664:

  SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation "qusuario.tu_permissao" does not exist  
  LINE 1: select * from "qusuario"."tu_permissao"                                              
                        ^ (SQL: select * from "qusuario"."tu_permissao")                       


In Connection.php line 330:

  SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation "qusuario.tu_permissao" does not exist  
  LINE 1: select * from "qusuario"."tu_permissao" 

In that I tried to change the orders of Migrations, I tried to create the table "tu_permissao" as it says in the error, but when I created and I php artisan migrate he returned to me that the table already exists.

My migrate:

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTuPermissaosTable extends Migration
{
    public function up()
    {
        Schema::create('qusuario.tu_permissao', function (Blueprint $table) {
            $table->bigIncrements('mid');
            $table->string('nome', 60);
            $table->string('mdesc', 120);
        });
    }

    public function down()
    {
        Schema::dropIfExists('qusuario.tu_permissao');
    }
}

Order of migrations:

migrations ordem

  • Why is one being executed SELECT in the bank when the migrate?

  • @Woss, I’m not sure, I suppose it’s part of migrate, but this error occurs as soon as I do the php artisan migrate

  • qusuario is the name give what? From the bank? How far do I know this is set up in .env or config/database.php and not in Migration itself, if the intention is to use point as prefix, I think it is already wrong, or at least disturbing Migration, since the point is used for specific things in querys. If the dot is just prefix even change all by _ everywhere referring to the table name

  • @Guilhermenascimento, the bank is already set up, my doubt is why I can’t perform the migrate

  • Database is one thing, table is another, if Migration generates the tables then being configured doesn’t make sense, unless you don’t know the difference, if the tables already exist in the database and you did them manually and it doesn’t make sense to use Migration. Otherwise pay attention to what I have already said and I am repeating, the . there in the Schema::create('qusuario.tu_permissao' does not seem to make sense, unless you want to force create a table in a specific bank, if that is the case then it is configuring wrong and probably (I can’t say) is disturbing the logic of Migration.

  • @Guilhermenascimento my database was configured with various Schemas, so the Schema::create('qusuario.tu_permissao')

  • But the migrates before the tu_permissao works normally, so I have no idea what.

  • As I have already said, I am almost certain that you imagine that it works with point to separate, but it does not work. As far as I know, but I could be wrong. At least perhaps not expected by the eloquent/eloquent

  • @Guilhermenascimento The System has been online for 11 years, I think it has been a while that works with the ., but as I said my doubt is not whether my bank is configured correctly, why have I done several migrations, but that one this specific error occurred

  • And you’re running some Seed? Because if the select is generated by Migration or Seed it is expecting something wrong and on top of that in a moment it separates "foo"."bar" and in the other he joins "foo.bar", as if it was just the table name using quotes.

  • 1

    The strangest thing is that you claim that the system has been online for 11 years, and Laravel is only 8 years old, that is, before it was done in a way and certainly not with Laravel’s Migrations

  • @Guilhermenascimento worse than no, I do not execute any seed.

  • @Guilhermenascimento I’m talking about the bank, the system used to run with CodeIgniter, based on the Laravel and henceforth this normal functioning. Mine migrations, mine seeders, run normally, only the one in question that gave this specific error.

  • Never mind, do with Migration and do without Migration (before) are two different things, something clearly was set wrong, I do not know if it is possible to set the bank directly in Scheme::create, as far as I know you create a connection for each bank and say this before create for each Migration. The only other possibility, if Laravel accepts to set the database directly in the string, would be if its postgres user is not allowed to create tables in the database qusuario

  • @Guilhermenascimento good thanks for trying to help, I will continue my tests here and any resolution, I return with the same in the post. :)

Show 10 more comments

1 answer

0

Thanks to those who tried to help me. I solved my problem as follows: There was a Provider that depended on my table, tu_permissao, every time I tried to run a command like php artisan migrate, mine Provider gave table error not found, but also could not create it, because of the error in question, noting this, I commented my function of Provider and surrounded the migrate normally. I will leave down the function that was preventing the creation of my table.

public function boot()
    {
            foreach ($this->listPerm() as $prr) {
            Gate::df($prr->name, function ($us) use ($prr) {
                return $us->validar($prr->prf) || ($us->su() || $us->adm());
            });
        }
    }

    public function listPerm()
    {
        return TuPermissao::with('prf')->get();
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.