Git Product home page Git Product logo

Comments (5)

ruckus avatar ruckus commented on August 20, 2024

The Postgres analog to MySQL auto_increment is serial. So the actual SQL would be:

CREATE TABLE animals (id serial, name text)

To achieve this:

$t = $this->create_table('animals');
// will automatically give you an `id` column of type `serial`

If you wanted a different name than id

// specify id=false so the default primary key is ignored
$table = $bm->create_table('animals', array('id' => false));
$table->column('user_id', 'integer', array('primary_key' => true, 'auto_increment' => true));
$sql = $table->finish();

from ruckusing-migrations.

0xff00ff avatar 0xff00ff commented on August 20, 2024

@ruckus thanks for answer, but just option 'primary_key' is not works. but if i set 'primary_key' as column type (not integer) it works perfect.

from ruckusing-migrations.

jaffarhussain1011 avatar jaffarhussain1011 commented on August 20, 2024

@ruckus i am able to create primary key with different column name but I want to specify my own keyname/constraint name so that sql for that should be like below
CONSTRAINT my_custom_key_anme PRIMARY KEY (user_id)
Is there any option to provide that in following query:
$table->column('user_id', 'integer', array('primary_key' => true, 'auto_increment' => true));

Thanks

from ruckusing-migrations.

ruckus avatar ruckus commented on August 20, 2024

Hi @jaffarhussain1011 - you cannot specify a constraint in the same column() method call. You'll need to finish creating the table and then run ad-hoc SQL to add that constraint, like:

// ... column calls
$table->finish();
$this->execute("ALTER TABLE foobar ADD CONSTRAINT ...");

from ruckusing-migrations.

jaffarhussain1011 avatar jaffarhussain1011 commented on August 20, 2024

Ok, Thanks for prompt reply.

from ruckusing-migrations.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.