database-schema

Adding an one-out-of-two not null constraint in postgresql

こ雲淡風輕ζ 提交于 2019-11-29 09:08:30
If I have a table in Postgresql: create table Education ( id integer references Profiles(id), finished YearValue not null, started YearValue, qualification text, schoolName text, studiedAt integer references Organizations(id), primary key (id) ); I need to make a constraint so that either schoolName or studiedAt needs to not be null (one of them has to have information in it). How do I do this? You can use a check constraint e.g. constraint chk_education check (schoolName is not null or studiedAt is not null) From the manual: A check constraint is the most generic constraint type. It allows

Foreign Key Referencing Multiple Tables

◇◆丶佛笑我妖孽 提交于 2019-11-29 08:37:54
I have a column with a uniqueidentifier that can potentially reference one of four different tables. I have seen this done in two ways, but both seem like bad practice. First, I've seen a single ObjectID column without explicitly declaring it as a foreign key to a specific table. Then you can just shove any uniqueidentifier you want in it. This means you could potentially insert IDs from tables that are not part of the 4 tables I wanted. Second, because the data can come from four different tables, I've also seen people make 4 different foreign keys. And in doing so, the system relies on ONE

Django and postgresql schemas

守給你的承諾、 提交于 2019-11-29 07:02:42
问题 I've been trying to solve this one all week, help very much appreciated. I have various schemas in a postgres db and I would like to be able to map to them from within the same or across different django apps. Some of the schemas are : samples excavation geophysics ... I have tried the recommended way, but I'm not getting any data to display from the schemas, I can only connect to the public schema with managed tables. Here is the database connections from the settings.py file. DATABASES = {

How to validate database schema programmatically in hibernate with annotations?

断了今生、忘了曾经 提交于 2019-11-29 04:52:06
It seems that org.hibernate.cfg.Configuration object can be used to perform validation programmatically, by calling the validateSchema method. However, this method needs dialect and databaseMetadata objects. I am using Spring and I can get a hold of AnnotationSessionFactoryBean object from spring context. So far I have the following code: AnnotationSessionFactoryBean factory = null; factory = (AnnotationSessionFactoryBean) context.getBean("AnnotationSessionFactory"); Configuration configuration = factory.getConfiguration(); //the following line does not work, ConnectionHelper hierarchy is not

Hierarchical Data - Nested Set Model: MySql

人盡茶涼 提交于 2019-11-29 04:31:16
I am just learning how to implement the Nested Set Model but still have confusion with a certain aspect of it involving items that may be part of multiple categories. Given the example below that was pulled from HERE and mirrors many other examples I have come across... How do you avoid duplication in the DB when you add Apples since they are multi-colored (i.e. Red, Yellow, Green)? Lachezar Balev You do not avoid duplications and the apple (or a reference to the apple) will be placed twice in your tree otherwise it won't be a tree but rather a graph. Your question is equally applicable if you

How to include MySQL database schema on GitHub?

萝らか妹 提交于 2019-11-29 02:22:34
问题 Stackoverflow and MySQL-via-command-line n00b here, please be gentle! I've been looking around for answers to my question but could only find topics dealing with GitHubbing MySQL dumps (as in: data dumps) for collaboration or MySQL "version control" via GitHub, neither of which tells me what I want to know: How does one include MySQL database schemas/information on tables with PHP projects on GitHub? I want to share a PHP project on GitHub which relies on the existence of a MySQL database

SQLite create pre-populated FTS table

好久不见. 提交于 2019-11-28 19:19:49
问题 Is there a way to create an FTS table in SQLite that is pre-populated with data from a SELECT query? I know it’s possible to create a regular table that is prepopulated with data from a SELECT: CREATE TABLE foo AS SELECT ref_id, name FROM other_table And we can create an FTS table like so: CREATE VIRTUAL TABLE bar USING FTS3(ref_id, name) The point of doing this is to update my app’s SQLite database schema while avoiding reading in all of the data from other_table . I’m really hoping there’s

Cannot create a new table after “DROP SCHEMA public”

℡╲_俬逩灬. 提交于 2019-11-28 19:09:22
Since I wanted to drop some tables and somebody suggested the below and I did it: postgres=# drop schema public cascade; DROP SCHEMA postgres=# create schema public; CREATE SCHEMA Then I got problem when creating a new database, such as: postgres=# create database test; CREATE DATABASE postgres=# \c test You are now connected to database "test" as user "postgres". test=# create table hi(id int primary key); *ERROR: no schema has been selected to create in* You can see I got error ERROR: no schema has been selected to create in* How can I restore the public schema? I suggest people never do

Database table design for scheduling tasks

China☆狼群 提交于 2019-11-28 18:54:21
I want to be able to create schedules that can be executed based on a fixed date, repeated daily, repeated on a particular day of the week, repeated on a particular month of the year, repeated on a particular date every year, and repeated at a particular time of the day. Please how do i go about building the database tables for this problem? Edit #1 Basically, i'm writing an application that allows users to schedule pre-configured greetings to be sent at various pre-configured times. I know i need a table that stores information about a schedule (ex. Christmas, Marketing One, ... | and when

schema builder laravel migrations unique on two columns

一个人想着一个人 提交于 2019-11-28 18:30:30
How can I set a unique constraints on two columns? class MyModel extends Migration { public function up() { Schema::create('storage_trackers', function(Blueprint $table) { $table->increments('id'); $table->string('mytext'); $table->unsignedInteger('user_id'); $table->engine = 'InnoDB'; $table->unique('mytext', 'user_id'); }); } } MyMode::create(array('mytext' => 'test', 'user_id' => 1); // this fails?? MyMode::create(array('mytext' => 'test', 'user_id' => 2); Collin James The second param is to manually set the name of the unique index. Use an array as the first param to create a unique key