SQLSTATE[42S01]: 基本表或视图已经存在:1050 表 ‘tags’ 已经存在

huangapple go评论114阅读模式
英文:

SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'tags' already exists

问题

无法为代码部分提供翻译。以下是要翻译的文本部分:

"When ran php artisan migrate it will show out error.

I try drop all file and install again, it show out this why?

2023_03_09_044748_create_tag_tables ................................. 6ms FAIL

Illuminate\Database\QueryException"

英文:

SQLSTATE[42S01]: 基本表或视图已经存在:1050 表 ‘tags’ 已经存在

SQLSTATE[42S01]: 基本表或视图已经存在:1050 表 ‘tags’ 已经存在

When ran php artisan migrate it will show out error.

I try drop all file and install again, it show out this why?

> 2023_03_09_044748_create_tag_tables ................................. 6ms FAIL
>
> Illuminate\Database\QueryException

答案1

得分: 1

你的迁移文件中有两个名为 "tags" 的表格,
_create_tags_table 和 _create_tag_table。
请检查这两个迁移中的创建方法,然后重命名或删除其中一个。

英文:

you have two tables named "tags" in your migration files
_create_tags_table and _create_tag_table
check the create method in both migrations and rename or delete one.

SQLSTATE[42S01]: 基本表或视图已经存在:1050 表 ‘tags’ 已经存在

答案2

得分: 1

你应该确保按照“Laravel方式”为表命名,并遵循它们的命名约定。

在这种情况下,你将迁移命名为..._create_tag_tables,但你创建的表名为tags。请确保迁移的命名方式相同。

你已经有一个创建tags表的迁移。如果你想要修改它,有两个选项:

如果尚未部署,你可以根据你的需求更新现有的迁移。然后运行php artisan migrate:fresh,这会清空数据库并重新设置(所有数据将丢失)。

但是绝不要修改已部署(或最好甚至已推送)的迁移,因为它们将不会再次运行。

在这种情况下,请创建一个新的迁移,更新已经存在的表格。

英文:

You should make sure to name tables the "Laravel way" and follow their naming conventions.

In this case, you named the migration ..._create_tag_tables, but the table you create is called tags. Make sure to name the migration the same way.

You already have a migration that creates the tags table. If you want to change that one, you have two options:

If not deployed yet, you can update the existing migration to your needs. Then run php artisan migrate:fresh, what will empty the database and set it up again (all data will get lost).

But never change deployed (or better even pushed) migrations as they will not be run again.

In that case, create a new migration that updates the already existing table.

答案3

得分: 0

问题出在2023_03_09_044748_create_tag_tables,将表名更改为tag

运行
composer dump-autoload,然后运行php artisan migrate:fresh

英文:

The problem is in 2023_03_09_044748_create_tag_tables, Change the table name to tag

Run
composer dump-autoload and then php artisan migrate:fresh

huangapple
  • 本文由 发表于 2023年3月9日 15:14:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/75681455.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定