Answer the question
In order to leave comments, you need to log in
Switching to postgresql (with mysql) in laravel migrations?
I have windows 10, postgresql 11 (+pgAdmin 4), php 7.2.11, laravel 5.4, locally on my computer. I am in the process of migrating from mysql to postgresql, namely rewriting migrations. It turns out that Lara is not well suited for posqtgresql, which is why I ask for help to figure it out correctly.
1. autoincrement
$tsble->autoincrement('id'); creates an integer field with DEFAULT nextval('users_id_seq'::regclass);
But in postgresql there is a serial type, it seems like it was created specifically for auto-increment IDs. Then you need to use it? But there is no such type in laravel migrations. Then leave the auto-increment in the migration as it is, and then after the migration manually change the field type to serial?
2. unsigned
It turns out it is not in postgresql. Replace with CHECK (field_name >= 0)? Or any other options (if any, why are they better)? And again, there is no check() in Lara migrations - do you have to fix it manually later in postgresql itself?
3. arrays
For mysql, I used string and wrote data there as json. For postgresql, I chose directly json for now. It is available in migrations. Or should I choose an array type? What is the difference between arrays and json in postgresql?
Something laravel, as I see it so far, is not well adapted to work with postgresql. The questions may seem silly to some, but nevertheless they came to me, I read them - I remained incomprehensible. In the lara there is nothing at all about the differences from Postgresql, so please help
Answer the question
In order to leave comments, you need to log in
1.autoincrementThe basic level is to add a field of the required type or change the field type manually through
2.unsigned
\DB::statement()
. 3. arraysBelieve it or not, they differ in that one is an array, and the other is json. And although they are sometimes similar, they are different data types. The documentation is in Russian, study.
In the lara there is nothing at all about the differences from PostgresqlThis is the point. The choice of a database is not related to Laravel, ideally it should not matter to you what kind of database it is. Therefore, Laravel's little bits support a more or less common set of data types, replacing them with others, as in the case of json and old versions of mysql.
Do not worry, as
Melkij correctly noted
As a rule, any non-standard things out of the box are supported a little less than nothing. I would even say everything that goes beyond the primitive. Moreover, in some languages, the drivers themselves impose restrictions. For example, PHP does not know how to work with PostgreSQL arrays, at all. As a rule, they bypass this matter like this, or immediately use jsonb
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question